Adding multiple class files to an Applescript Studio project

How do I get AS Studio to recognize classes in seperate .applescript files? This one’s got me stumped.

I have a project with a base Application.applescript and a second class.applescript file.

The base file should be able to create an instance of the class located in the class file. The build works fine, but when I run the app I always get the following error: “The variable myClass is not defined”.

How the heck to I get AS Studio to realize that it should use the other .applescript files too???

Thanks if you can help me with this one!
-Chris

Use “load script” (see Standard Additions).

Many, many thanks – I knew it was stupid/basic, but for the life of me, I just couldn’t find an example anywhere!

:wink:

-Chris

PS. Will post again shortly with the next getting started q! :cool:

Browser: Firefox 1.0.5
Operating System: Mac OS X (10.4)

Thanks for pointing me in the right direction.

I found an example in the AS Studio example code that finally gave me what I needed to figure out what’s going on with AS when trying to use external script files to organize classes for a larger project. The original example code is located in the Examples:Applescript Studio:Unit Converter.

Here’s a short example that might come in handy for others trying to come to grasps with external class files and Applescript Studio:


-- In the Application.applescript file
on open names
   set ctrlLib to my loadScript("controller")     -- load the script located in the file "controller.applescript"
   set ctrl to controller of ctrLib                     -- store a copy of the controller object thats defined in "controller.applescript"
   display dialog(mGetUser() of ctrl as text)   -- Call a method on the controller object & display the result in a dialog
end open

-- Function that returns the path to the compiled scripts for this app.
on pathToScripts()
   set appPath to (path to me from user domain) as text
   return (appPath & "Contents:Resources:Scripts:") as text
end pathToScripts

-- Function that handles the loading of the external file.
on loadScript(scriptName)
   set appPath to (path to me from user domain) as text
   return load script file (my pathToScripts() & scriptName & ".scpt")
end loadScript

The Controller object is defined in a seperate applescript file called “controller.applescript”. Here’s the code of the file that is used in the above example.


script controller

   property user : "Mike"

   on mGetUser()
      return user
   end mGetUser

end script

This should show a dialog that says “Mike” (if I typed everything in correctly here!).

I found some other examples here and in the Applescript Studio docs, but they were all rather vague (doing to much other stuff at the same time).

I hope this helps someone avoid the hours of frustrating searching that I had to do to find this! :wink:

Cheers,
-Chris

Browser: Firefox 1.0.5
Operating System: Mac OS X (10.4)