stumped: set script of buttons at runtime

Sarah Reichelt sarahr at genesearch.com.au
Thu Jun 16 19:02:42 EDT 2005


> I've been battling this problem for a few days and have no idea  
> where to look next.  Originally I thought it had to do with global  
> variable issues between stacks.  However, after MUCH hair-pulling  
> it appears the problem has to do with setting the script property  
> of buttons dynamically ...or so I think...Keep in mind the  
> following code works perfectly in development. That is, the last  
> line of the mouseUp handler in the hidden defaultButton says  
> "answer the script of me".  In development, after all the buttons  
> have been created, clicking any of the buttons generates a dialog  
> box and the appropriate script.  In standalone mode, the script of  
> all the dynamically created buttons is empty...even the "answer"  
> command on the last line on makeButtons returns empty

If your template script is more than 10 lines, it will work in the  
IDE, but not in a standalone as you are limited in creating new  
scripts there. However if you have multiple buttons all with the same  
script, then it would be easier to place the script higher in the  
message path and have them all use the same script.

There are 2 ways you could do this:

set the script of each button to:
   on mouseUp
     doMyButtonhandler
   end mouseUp
and have all the scripts in the "doMyButtonHandler" handler in the  
card or stack script.

Alternatively, just have a mouseUp script in the card or stack script  
containing all your button script and check "the target" each time it  
is called to see whether it is one of the buttons that should use the  
handler.

HTH,
Sarah



More information about the use-livecode mailing list