How/When are behavior references resolved?

Ken Ray kray at sonsothunder.com
Fri Jul 15 19:59:35 EDT 2011


On Jul 15, 2011, at 3:29 PM, Pete wrote:

> I'm having a problem with behaviors not being resolved in my application
> stack.
> 
> I have two stack files, lets call them library.livecode and
> application.livecode.  The script of the main stack of library.livecode has
> handlers that I use in application.livecode by issuing a "start using"
> command.
> 
> library.livecode also contains a substack named Behaviors whose card has a
> bunch of buttons whose scripts I want to use as behaviors in
> application.livecode butthe "start using" command doesn't seem to make the
> behaviors available to the controls in application.livecode, by which I mean
> they act like they don't have a behavior defined.
> 
> I can fix this by setting the stackFiles of the main stack of
> application.livecode to "Behaviors,<path to library.livecode>".  I have to
> reference the Behaviors substack, not the main stack of library.livecode for
> this to work.
> 
> I guess I'm wondering if this is the appropriate way to deal with this
> situation or if there's a cleaner way to do it.

You're right - putting a stack into use doesn't load it into memory (e.g. it's not in the mainstacks), so the behaviors go unresolved. Here's two ways to do it (other than the one you described):

1) Open the library invisibly (I do this by trapping "on libraryStack":

on libraryStack
  if the target is me then
    open inv stack (the short name of me)
  end if
end libraryStack

2) The "datagrid" trick - if you use "there is a stack" then it loads a stack into memory but doesn't actually open it:

get (there is a stack <pathToStack>)



Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/	




More information about the use-livecode mailing list