Page 1 of 1

Common Handler for a number of Buttons

Posted: Fri Sep 26, 2008 2:36 am
by bjb007
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.

Posted: Fri Sep 26, 2008 3:30 am
by FourthWorld
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