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 » Tue Aug 30, 2011 6:48 pm

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: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Recurring events

Post by jmburnod » Tue Aug 30, 2011 7:04 pm

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: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Recurring events

Post by mwieder » Tue Aug 30, 2011 7:39 pm

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: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Recurring events

Post by dunbarx » Tue Aug 30, 2011 7:59 pm

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: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Recurring events

Post by mwieder » Tue Aug 30, 2011 8:55 pm

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 » Wed Aug 31, 2011 9:35 am

Thank you all!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”