Recurring events

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

Post Reply
cu3e
Posts: 46
Joined: Mon May 23, 2011 10:03 am

Recurring events

Post 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?
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2734
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Recurring events

Post by jmburnod »

Hi cu3e,

Two ways

1. Using group
2. Using behavior, (you can check it in LC dictionary)

Best regard

Jean-Marc
https://alternatic.ch
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3582
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Recurring events

Post 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
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10504
Joined: Wed May 06, 2009 2:28 pm

Re: Recurring events

Post 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
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3582
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Recurring events

Post by mwieder »

The OP did specifically say all buttons...

But, yes... Craig wrote a much better description of what my example is doing.
cu3e
Posts: 46
Joined: Mon May 23, 2011 10:03 am

Re: Recurring events

Post by cu3e »

Thank you all!
Post Reply