Page 1 of 1
Recurring events
Posted: Tue Aug 30, 2011 6:48 pm
by cu3e
Hello, me again
I want to play a sound when clicking on a button. I know how to do it. But do I have to put the script into every button I want to play that sound file or is there a way to make it easier and automatic apply a command to
all buttons on the stack?
Re: Recurring events
Posted: Tue Aug 30, 2011 7:04 pm
by jmburnod
Hi cu3e,
Two ways
1. Using group
2. Using behavior, (you can check it in LC dictionary)
Best regard
Jean-Marc
Re: Recurring events
Posted: Tue Aug 30, 2011 7:39 pm
by mwieder
A third way (in card or stack script):
Code: Select all
on mouseUp
if word 1 of the name of the target is "button" then
-- make a jazz noise here
end if
end mouseUp
Re: Recurring events
Posted: Tue Aug 30, 2011 7:59 pm
by dunbarx
The "mouseUp" message is generated when you click within a button's area. If the message is not trapped by a handler in that button script, it passes through a hierarchy of objects, including the card and the stack. So if you have a mouseUp handler in the card script, it will be trapped and executed.
What Mark implied is that you can check the source of the message (the "target") and only execute if that target meets some criteria. You may want to somehow set apart the buttons that will invoke the play routine, as opposed to others that may not. This is all just a lesson on LC basics. So if all the buttons that will cause the sound to play are named:
play1, play2, play3, etc., then you might write
Code: Select all
on mouseUp
if word 1 of the name of the target is "button" and the name of the target contains "play" then
-- make a jazz noise here
end if
end mouseUp
There are many other properties that might be similarly employed if the name is not convenient.
Craig Newman
Re: Recurring events
Posted: Tue Aug 30, 2011 8:55 pm
by mwieder
The OP did specifically say all buttons...
But, yes... Craig wrote a much better description of what my example is doing.
Re: Recurring events
Posted: Wed Aug 31, 2011 9:35 am
by cu3e
Thank you all!