Standalone App Question

Trevor DeVore lists at mangomultimedia.com
Tue Aug 9 13:36:40 EDT 2005


On Aug 9, 2005, at 7:15 AM, David Burgun wrote:

> Splash.rev
> Stacks/Stack1.rev
> Stacks/Stack2.rev
> Stacks/Stack3.rev
>
> In the Splash Stack, I have setup the Standalone options as follows:
> In the Copy Files Section: I have Stacks/Stack1.rev, Stacks/ 
> Stack2.rev and Stacks/Stack3.rev
>
> From this I have the following questions:
>
> 1.  How do I setup the externals property in a Standalone App
>
> 2.  I assume I have to do it in Splash.rev, is this correct or do I  
> have to do in seperately in each on Stack1.rev, Stack2.rev and  
> Stack3.rev
>
> Any help on this would be really appreciated.

You can do this a number of different ways.  One way is to set the  
externals property of the "Splash.rev" stack.  When you build it as a  
standalone it will load the external when the app launches.  The  
trick is to use the "Splash.rev" as a library so that the external  
handlers are available to all stacks running in the standalone.  So  
in stack "Stack1.rev" you might do the following:

start using stack "Splash.rev"

Now you can call any of handlers that are available  
(externalFunctions of stack "Splash.rev" and externalCommands of  
stack "Splash.rev") in any stack.

That being said, I prefer a different method when dealing with  
externals.

When using externals I like to be able to load/unload the external  
whenever I want.  This is necessary if you want the ability to update  
an external while your application is running.  Now, in order to  
unload an external it must be attached to a stack that 1) has the  
destroyWindow property set to true and 2) is open, not just in  
memory.  With that in mind, whenever an application launches it can  
create a stack at runtime (never actually exists on disk) that has  
the properties we need.  For example:

on loadAppExternals
     local tExternals

     ----------
     --> EXTERNALS
     ----------
     put "myExternal.bundle" &cr& "myExternal.dll" into tExternals

     ----------
     --> CREATE EXTERNALS STACK IN MEMORY
     ----------
     if tExternals <> empty then
         if there is not a stack "myExternals" then
             reset templateStack
             set destroyWindow of templateStack to true
             set destroyStack of templateStack to true
             set visible of templateStack to false
             set externals of templateStack to tExternals

             create stack "myExternals"
             reset templateStack
         end if

         go stack "myExternals"
         start using stack "myExternals"
     end if
end loadAppExternals

Now you can call loadAppExternals whenever you need to load externals  
for your application.  If you need to unload the externals just close  
the stack:

close stack "myExternals"

The externals will be unloaded from memory and you can update the  
external files on disk.

If you ever need to check if an external loaded correctly or is  
available you can check the externalPackages property of the  
"myExternals" stack.  Every external has a string identifier that the  
person who made the external assigns to it.  This shows up in the  
externalPackages property of the stack only when the external has  
successfully loaded.  So if you have an external that is identified  
with the string "MySuperExternal" you could have some code like this:

on checkAppExternals
     local tRequiredExternals,tExternal

     if there is not a stack "myExternals" then
         answer "You didn't bother loading the externals stack.  Try  
again."
         return empty
     end if

     put "MySuperExternal" into tRequiredExternals

     repeat for each line tExternal in tRequiredExternals
         if tExternal is not among lines of externalPackages of stack  
"myExternals" then
             answer "Oh where, oh where has my external gone?"
             return empty
         end if
     end repeat
end checkAppExternals

This method of working with externals has proven to work really well  
for me.


-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com





More information about the use-livecode mailing list