Recurring events
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Recurring events
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?
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?
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Recurring events
Hi cu3e,
Two ways
1. Using group
2. Using behavior, (you can check it in LC dictionary)
Best regard
Jean-Marc
Two ways
1. Using group
2. Using behavior, (you can check it in LC dictionary)
Best regard
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Recurring events
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
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Recurring events
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
There are many other properties that might be similarly employed if the name is not convenient.
Craig Newman
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
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Recurring events
The OP did specifically say all buttons...
But, yes... Craig wrote a much better description of what my example is doing.
But, yes... Craig wrote a much better description of what my example is doing.