play sound on "began" code freezes corona :/

i'm trying to make a "sound" when i taps (began phase only) on the ball. it freezes corona simulator and crashes. here is my code:

function onTouch(event)
if event.phase == "began" then
local balltap = media.newEventSound( "balltap.wav" )
local playballtap = function()
media.playEventSound(balltap)
end
media.playEventSound( "balltap.wav", onComplete )

i'm trying to understand lua, its making sense (little) so far. i know i can learn it but baby steps right?

so is my code wrong? i've ben trying to play sound and failed at every attempted except this one. either way can someone point me in the right direction

Hey there, this should do exactly what you want - although you will need to change "ouch" to your own name, in this case ballTap.

1
2
3
4
5
6
7
8
9
10
11
local background = display.newRect( 0, 0, 320, 480 )
background:setFillColor (100, 200, 255)
 
local ball = display.newCircle( 160, 200, 30 )
 
local ouch = media.newEventSound( "ouch.wav" )
 
local function playOuch ()
        media.playEventSound(ouch)
end
ball:addEventListener("tap", playOuch)

PS - The code you put above only has one "end", it should have three. One for each function plus one for the if statement ;)

views:1277 update:2011/10/17 8:58:49
corona forums © 2003-2011