stumped: set script of buttons at runtime

Emilio Gagliardi emilio at ualberta.ca
Wed Jun 15 17:43:57 EDT 2005


Hi All,
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


on makeButton buttonText

   set the style of the templateButton to "Button"
   set the label of the templateButton to buttonText
   set the visible of the templateButton to false
   set the width of the templateButton to BUTTON_WIDTH
   set the height of the templateButton to BUTTON_HEIGHT
   set the opaque of the templateButton to false
   set the textAlign of the templateButton to "center"
   set the threed of the templateButton to false
   set the showborder of the templateButton to false
   set the autohilight of the templateButton to false
   set the textFont of the templateButton to "verdana"
   set the textSize of the templateButton to "16"
   set the location of the templateButton to DEFULT_LOCATION

   lock messages
   create button buttonText
   unlock messages

   set the script of button buttonText to the script of button  
"defaultButton" of card "defaultBlock"
   set the location of it to getNextButtonLocation()
   set the myHome of it to the location of it

   set the visible of button buttonText to true
   answer the script of button buttonText

end makeButton

All the buttons are exactly the same except for their label.  They  
all have the same functionality so i store the script for the buttons  
in a button whose visibility is set to false.  In development mode  
everything works perfectly.  All the buttons appear, they all contain  
the script from the hidden button, and they all use their respective  
scripts as intended.  However, if I open the stack using the "go"  
command from within another stack, the above makeButton command does  
not set the script property of the buttons and hence none of them  
work.  If I set the visibility of the original hidden button to true,  
it works fine.  So for some reason, setting the script of a button at  
runtime does not seem possible.  Does anyone know what I'm doing  
wrong here??

Completely frustarted,
Emilio


More information about the use-livecode mailing list