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
Detect a button click (Script not in button): Possible?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Detect a button click (Script not in button): Possible?
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 scriptNow 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
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
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?
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:
Again, thank you very much.
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"
Re: Detect a button click (Script not in button): Possible?
Hi Cheong,
you can make this a bit shorter, "the long ID of btn..." is only neccessary for the actual BEHAVIOR button!
Best
Klaus
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"
Klaus
Re: Detect a button click (Script not in button): Possible?
Hi Klaus,
I see!
Thanks for the guide.
I see!
Thanks for the guide.