Event Sound set on timer, stop when button clicked

I have an event sound that is on a timer delay. when I click a button I want the event sound to not play at all [import]uid: 14967 topic_id: 8645 reply_id: 308645[/import]

So you want to cancel the timer?

There is a “timer.cancel()”

If you want to be super sure and stable, I’d go with:

[lua]if timerName then timer.cancel(timerName) end[/lua] [import]uid: 45459 topic_id: 8645 reply_id: 31021[/import]

this will stop the sound from playing all together? the button brings you to a new page when pressed, and i cant have the sound with the timer to play, when it goes to the new page [import]uid: 14967 topic_id: 8645 reply_id: 31027[/import]

If the sound will play based on a timer, then by canceling the timer nothing should play the sound. [import]uid: 45459 topic_id: 8645 reply_id: 31030[/import]

sorry, im not really sure how to set this up. this is what i have so far

local ahHelloSound = media.newEventSound( "sounds/ahHello.caf" )  
   
local playAhHello = function()  
 media.playEventSound( ahHelloSound )  
end  
timer.performWithDelay( 5000, playAhHello, 1 )  

I just dont no how to stop the sound when the button is tapped when there is a timer involved [import]uid: 14967 topic_id: 8645 reply_id: 31032[/import]

[lua]local ahHelloSound = media.newEventSound( “sounds/ahHello.caf” )

local playAhHello = function()
media.playEventSound( ahHelloSound )
end
hellotimer = timer.performWithDelay( 5000, playAhHello, 1 )

local function pressbutton (event)
–your code to change to a new page/screen here
if hellotimer then
timer.cancel(hellotimer)
end
yourbutton:addEventListener(“tap”, pressbutton)[/lua]

Does that make sense?

Peach :slight_smile: [import]uid: 10144 topic_id: 8645 reply_id: 31634[/import]

Thank You!!! it is working perfectly! [import]uid: 14967 topic_id: 8645 reply_id: 31735[/import]

Fantastic! I love that feeling when you get something solved :smiley:

Good luck with the rest of your project :slight_smile:

Peach [import]uid: 10144 topic_id: 8645 reply_id: 31766[/import]

Thank You!!! [import]uid: 14967 topic_id: 8645 reply_id: 31776[/import]