stopping and disposing of sound question

I have 12 buttons on my main menu page, and each has a different sound when you click on one of them, do I have to add 12 event listeners to each stop and dispose function of each sound anytime, anyone of the buttons are hit? If that makes any sense

Thanks [import]uid: 14967 topic_id: 9421 reply_id: 309421[/import]

Hmm… I haven’t tested this personally, but you can try something like this:

[lua]local buttonPress = function (event)
if event.phase == “Released” then
if button1.press == true then
– do something
elseif button2.press == true then
– do something else
end
end
end

– let me know what the result is.[/lua]

check out my game:
Touch Cannon – a **FREE** game

please rate :slight_smile:

[import]uid: 12455 topic_id: 9421 reply_id: 34468[/import]

Alternatively, you can write just one audio callback function which you reuse for everything you play.

function MyAudioCallback(event)  
 audio.dispose(event.handle)  
end  
  
-- sound is the handle loaded by audio.loadSound or audio.loadStream  
function MyPlaySound(sound)  
 audio.play(sound, {onComplete=MyAudioCallback})  
end  

If you plan to reuse these sounds a lot and aren’t tight on memory, you might just keep the sounds in memory and skip disposing them. [import]uid: 7563 topic_id: 9421 reply_id: 34476[/import]

@teex84 and @ewing Thanks for the advice, I will give them a try.

I am using the sounds a lot, so I may just keep them loaded in memory. [import]uid: 14967 topic_id: 9421 reply_id: 34480[/import]

Nothing to contribute… but just wanted to comment/ask…
are you Matthew “Chandler” Perry ? :smiley: hehheheh… [import]uid: 48521 topic_id: 9421 reply_id: 34485[/import]

@chinmay.patil hahahaha I get that a lot :slight_smile: [import]uid: 14967 topic_id: 9421 reply_id: 34488[/import]