Parent/Inheritance Question

Hi All,
I was wondering if it were possible to have a second applescript file in a project be the child of the appdelegate script file. Something like this:


script mySecondScriptFile
property parent : class "myFIrstScriptFileAppDelegate"

--a bunch of stuff
end script

It should be doable within the same script file (I think??), but will it work with a second script file that is then loaded via “load script”? I tried it, but couldn’t get it to work.

Inheritance like that is limited to Objective-C superclasses. But if you use load script, the loaded script’s parent is the script that loads it.

Thanks Shane. I didn’t know that about loaded scripts. If I may follow up, what happens when the loaded script has the property parent: class “NSObject” line? A script can’t have two parents can it? I ask because it seems like it might be useful if the loaded scripts can have access to the loading scripts handlers and properties via inheritance, but I can’t make it work. BTW, I picked up your book and I’ve just started getting into it, so if it’s covered in there somewhere, feel free to just refer to a page number :).

No, it can’t, and I’m not sure what the result will be – I’ve never tried specifying a parent in a loaded script. Just add the line:

log | superclass|()

to the loaded script, and you can probably tell me :slight_smile:

Hmmm, curiosity got the better of me. Looks like NSObject is the parent, and it gives an error if it’s not. That sort of fits in with the following…

You can get at the properties, but you can’t call the handlers.

IMO, you’ll probably be better off to put the stuff you’re loading in separate classes, rather than rely on load script. Then you can get at both properties and handlers. It also lets you implement setters and getters for your properties, which can be useful at times. The downside is that you’ll need to follow the Cocoa naming conventions, and coerce results and arguments (because they’re all travelling via Cocoa-land).

The ‘Handlers as Methods’ chapter of the Reference Section covers the issues with calling methods between script objects. And thanks for buying the book!