Page 1 of 1
Detect a button click (Script not in button): Possible?
Posted: Mon Nov 02, 2015 8:33 am
by Cheong
Hi readers,
Is is possible to detect a button click even without assigning a script to that button? For example, I use card script to detect whether a button is clicked and run a function on that instant.
This is for the purpose of clicking a button generated by script.
If it is possible, any idea how?
Thanks
Re: Detect a button click (Script not in button): Possible?
Posted: Mon Nov 02, 2015 9:22 am
by SparkOut
Er, yes. This is fundamental to the "message" paradigm of LiveCode. Look up about the message path in Richard Gaskin's hyper-useful article here
http://www.fourthworld.com/embassy/arti ... _path.html
In the meantime, make a new card and drop three buttons on it, give them separate names, but do not edit the buttons' scripts. In the card script
Code: Select all
on mouseUp
answer the short name of the target
end mouseUp
Now click each of the buttons and see what you get.
Then, click on the card anywhere but on a button. See what happens there, and how you need to work out what your handlers need to cater for?
But it sounds like longer term you want to read up on Behaviors
Re: Detect a button click (Script not in button): Possible?
Posted: Mon Nov 02, 2015 9:52 am
by Cheong
Hi SparkOut,
Thank you for the immediate response. I have read the details in the link you showed me, then finally figured out what is the solution.
I passed on the behaviors from a preset button to another using the code here:
Code: Select all
set the behavior of the long id of button ("Button" & x) to the long id of button "ButtonReactionSample"
Again, thank you very much.
Re: Detect a button click (Script not in button): Possible?
Posted: Mon Nov 02, 2015 1:24 pm
by Klaus
Hi Cheong,
you can make this a bit shorter, "the long ID of btn..." is only neccessary for the actual BEHAVIOR button!
Code: Select all
set the behavior of button ("Button" & x) to the long id of button "ButtonReactionSample"
Best
Klaus
Re: Detect a button click (Script not in button): Possible?
Posted: Tue Nov 03, 2015 2:15 am
by Cheong
Hi Klaus,
I see!
Thanks for the guide.