Common Handler for a number of Buttons

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Common Handler for a number of Buttons

Post by bjb007 » Fri Sep 26, 2008 2:36 am

Tried a few variations in an attempt to
find a way of using the same code for
a number of buttons without having to
repeat the code in each button handler.

Is there a way to have one line of code
in each "mouseUp" handler which directs
to common code elsewhere?

Expect it might need 'with message' to
pass the click to the common code but
haven't been able to find something that
works.
Life is just a bowl of cherries.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Post by FourthWorld » Fri Sep 26, 2008 3:30 am

You could put this in each button:

Code: Select all

on mouseUp
  DoSomething
end mouseUp
And then put this in your card script:

Code: Select all

on DoSomething
  --- stuff goes here
end DoSomething
But that's a lot of work, since you'd have to copy and paste that handler into each button. I'm too lazy for that.

So alternatively you could put a mouseUp handler right in the card script, provided you have some way to distinguish the buttons you want to share the behavior.

Let's assume you have a custom property in each of these buttons named "uClass", with a value of "SpecialButton". Then you could have a mouseUp handler in the card script (or anywhere else later in the message path) like this:

Code: Select all

on mouseUp
  if the uClass of the target is "SpecialButton" then
      DoSomething
  else
     pass mouseUp
  end if
end mouseUp
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”