Prevent triggering event multiple times

I have a couple of buttons.
When you tap on a button it plays a bunch of sounds in sequence.
The problem is when you tap twice it will play those sounds at the same time and the app will crash.
What is the best way to prevent that from happening?

[import]uid: 24363 topic_id: 11887 reply_id: 311887[/import]

I think you should use a flag to keep track of whether sound is already playing.
In your touch listener you can set the flag to true the first time and not play music if the flag is true.
[import]uid: 50371 topic_id: 11887 reply_id: 43341[/import]

I’d go with ranjit’s suggestion; simple and clean :slight_smile: [import]uid: 52491 topic_id: 11887 reply_id: 43394[/import]

Or remove the event listener on the button when its pressed, and add it again with timer.performWithDelay with the delay set to the time it takes for all your stuff to happen :slight_smile:

I avoid flags wherever possible - they are required in a lot of cases, but people scream flag too much! :smiley: [import]uid: 8872 topic_id: 11887 reply_id: 43586[/import]

I did some reading and tried out audio.isChannelActive()

This method seems to be working great. It tells me whether there
is a sound still playing and if there is I do not trigger any
additional sounds.

http://developer.anscamobile.com/reference/index/audioischannelactive
Thank you all for replies.
[import]uid: 24363 topic_id: 11887 reply_id: 44043[/import]