LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
I am dynamically reassigning button scripts as part of a menu system. The following command works once on buttons but doesn't seem to subsequently work. The script is less than 10 lines, is there also an unmentioned limit on how many times you can reassign a button's script?
Type Chunk: can't set property
Object application
Line set the script of button theButton to theScript
Hint on mouseUp
command assignMenuButton buttonPos, behindImage, buttonBehavior
put ("buttonMenu" & buttonPos) into theButton
put "on mouseUp" & cr & \
" " & buttonBehavior & " " & buttonPos & cr& \
"end mouseUp" into theScript
set the script of button theButton to theScript
put behindImage into buttonsCurrent[buttonPos,"image"]
put "true" into buttonsCurrent[buttonPos]
end assignMenuButton
Last edited by SteveTX on Tue Jul 09, 2013 7:42 am, edited 1 time in total.
Discovered the issue, I think. The error is dependent upon executing the script assigned to the button. Message path was mouseUP on button "MenuButton1" calling a command that called a command that would modify the script of button "MenuButton1", thus making it a self-modifying handler that violates the "script" command.
put the modifying script into a separate handler, then call that handler after some time has passed. That way the mouseUp handler has a chance to finish up and get out of the message path.
-- in mouseButton1 script
on mouseUp
-- local buttonNumber
--do things here
put 1 into buttonNumber
send "deleteAndRecreateMe buttonNumber" to this stack in 10 milliseconds
end mouseUp
-- in stack script
on deleteAndRecreateMe pNum
-- if there is a button "MenuButton" & pNum then
-- you know what to do here
end deleteAndRecreateMe