Do something when any button is clicked

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm
Location: Croatia

Do something when any button is clicked

Post by croivo » Fri Apr 03, 2015 6:36 pm

I have a group of buttons that behaves like a 'custom-dropdown' menu. When I click on the button, the dropdown menu appears. The problem is that I can't make group to hide when any other button (with script) in stack is clicked.

I tried to add this on card and stack script:

Code: Select all

on mouseUp
   answer "On mouseUp handler it works!"
end mouseUp

on mouseDown
   answer "On mouseDown handler it works!"
end mouseDown
It works only on mouseDown handler... but why it doesn't on mouseUp?

Klaus
Posts: 11202
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Do something when any button is clicked

Post by Klaus » Fri Apr 03, 2015 6:59 pm

Hi croivo,

sounds funny, but the "mouseup" message gets "eaten" by the modal ANSWER dialog! :D
Replace ANSWER with PUT and you will see what I mean.


Best

Klaus

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm
Location: Croatia

Re: Do something when any button is clicked

Post by croivo » Fri Apr 03, 2015 9:46 pm

Hm...

I actually have this code on card:

Code: Select all

on mouseUp
   set the visible of group "myGroup" to false
end mouseUp
But it's not working...

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

Re: Do something when any button is clicked

Post by SparkOut » Fri Apr 03, 2015 10:19 pm

Are you clicking on the card when you want the group to hide? Or another button?
If a button, what script does it contain? By default, a new button will have an empty on mouseUp handler. That would trap the mouseUp message stopping it from reaching the card but do nothing, unless you delete the empty handler or pass mouseUp within it.

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm
Location: Croatia

Re: Do something when any button is clicked

Post by croivo » Fri Apr 03, 2015 10:25 pm

Clicking on a button...

The button has a lot of code on mouseUp handler...

It's not handy to add "set the visible of group "myGroup" to false" to all buttons manually...

msellke
Posts: 22
Joined: Mon Oct 21, 2013 2:57 am

Re: Do something when any button is clicked

Post by msellke » Fri Apr 03, 2015 11:52 pm

Hi crovio,

Have you tried putting pass mouseUp into your mouseUp handler in the button.
I am still learning much of livecode myself but I believe this will allow the message to pass along the message path.

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

Re: Do something when any button is clicked

Post by SparkOut » Sat Apr 04, 2015 12:25 am

Exactly, if you don't include a "pass mouseUp" statement in the mouseUp handler of the button then the mouseUp message will stop once caught by the button handler and never reach the card.
You could possibly make things easier to maintain if you can use behaviors or simply break out the button scripts to call a generic command but we'd need to see more code. At the least though, you could add "hideTheGroup" to the button scripts and in the card script have

Code: Select all

on hideTheGroup
   set the visible of group "myGroup" to false
end hideTheGroup

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5106
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Do something when any button is clicked

Post by jacque » Sat Apr 04, 2015 5:28 pm

SparkOut wrote: By default, a new button will have an empty on mouseUp handler. That would trap the mouseUp message stopping it from reaching the card but do nothing, unless you delete the empty handler or pass mouseUp within it.
Actually a new button has no script. LC inserts the empty mouseUp handler template as a convenience the first time you open the button script for editing. If you hit the Enter key, you end up saving the blocking empty handler.

This can be either convenient or confusing. If you ask for the script of a new button in the message box it comes back empty. Some other controls provide the same kind of default template handlers that don't really exist until compiled.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Do something when any button is clicked

Post by SparkOut » Sat Apr 04, 2015 9:54 pm

That's interesting. I've never tried getting the script in that way before looking in the script editor. It does make perfect sense, of course, and I have used new buttons without having to delete an empty handler before, triggering mouseUp further up the message path, so I was not thinking clearly. It's just that first view in the editor that creates the empty handler, which if applied, will block the mouseUp from travelling up the message path.
Of course, in the OP's case, the buttons do contain script. Just not a "pass mouseUp" statement, or a call to a handler to close the group.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”