Detect a button click (Script not in button): Possible?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Cheong
Posts: 30
Joined: Tue Oct 27, 2015 7:49 am

Detect a button click (Script not in button): Possible?

Post by Cheong » Mon Nov 02, 2015 8:33 am

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

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Detect a button click (Script not in button): Possible?

Post by SparkOut » Mon Nov 02, 2015 9:22 am

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

Cheong
Posts: 30
Joined: Tue Oct 27, 2015 7:49 am

Re: Detect a button click (Script not in button): Possible?

Post by Cheong » Mon Nov 02, 2015 9:52 am

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.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Detect a button click (Script not in button): Possible?

Post by Klaus » Mon Nov 02, 2015 1:24 pm

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

Cheong
Posts: 30
Joined: Tue Oct 27, 2015 7:49 am

Re: Detect a button click (Script not in button): Possible?

Post by Cheong » Tue Nov 03, 2015 2:15 am

Hi Klaus,

I see!

Thanks for the guide.

Post Reply