i want to kill the ball

i want that a lot of balls come off the top of the screen and when i touch one.she disappears, and when i touch other she disappears too (sorry for the bad english,i am from venezuela, i have 13 years old and i am very very noob with corona sdk)
this is my code

[code]
– -- add physics engine, start up the engine, and apply gravity
local physics = require(“physics”)
physics.start()
– Set gravity to act “down” (ie, toward the bottom of the device )
physics.setGravity (-0.4, 9)
–set background image
local background = display.newImage( “background.jpg” )
– A touch listener to remove rocks
local removeBody = function( event )
local t = event.target
local phase = event.phase

if “began” == phase then
t:removeSelf() – destroy object
end

– Stop further propagation of touch event
return true
end

–add floor image and position
local floor = display.newImage(“bar.png”)
floor.y = display.contentHeight/1.03
– turn floor into physics body
physics.addBody(floor,“static”)

–set ball to stage and position
local function spawnBall()
ball =display.newImage(“bead2.png”)
ball.x = math.random ( 320 )
ball.y = -20
– turn bead into physics body
physics.addBody(ball,{bounce = 0.1 } )
end
timer.performWithDelay( 500,spawnBall,50)
ball:addEventListener( “touch”, removeBody ) – assign touch listener to rock
balls[#balls + 1] = ball
end

[import]uid: 179948 topic_id: 31381 reply_id: 331381[/import]

rflorezablan: Looks close what you have but I think you need to move your touch listener inside your SpawnBall() function.

Also do you too many end statements (maybe you haven’t posted your full code) ?

Dave [import]uid: 117617 topic_id: 31381 reply_id: 125466[/import]

This will give you infinite balls
[lua]local j = 1
ball = {}

function createBall()
ranX = math.random( w/2-5, w/2+5 )
ball[j] = display.newCircle( ranX, 40, 2 )
ball[j]:setFillColor(0,0,255)
ball[j].name = “ball”
ball[j]:addEventListener(“collision”, ball[j])
physics.addBody(ball[j],“dynamic”, {bounce=.1, radius = 5,density = .3, friction=1 })
group:insert(ball[j])
j = j + 1
end

tmr1 = timer.performWithDelay( 400, createBall,-1 ) [import]uid: 75779 topic_id: 31381 reply_id: 125452[/import]

rflorezablan: Looks close what you have but I think you need to move your touch listener inside your SpawnBall() function.

Also do you too many end statements (maybe you haven’t posted your full code) ?

Dave [import]uid: 117617 topic_id: 31381 reply_id: 125466[/import]

This will give you infinite balls
[lua]local j = 1
ball = {}

function createBall()
ranX = math.random( w/2-5, w/2+5 )
ball[j] = display.newCircle( ranX, 40, 2 )
ball[j]:setFillColor(0,0,255)
ball[j].name = “ball”
ball[j]:addEventListener(“collision”, ball[j])
physics.addBody(ball[j],“dynamic”, {bounce=.1, radius = 5,density = .3, friction=1 })
group:insert(ball[j])
j = j + 1
end

tmr1 = timer.performWithDelay( 400, createBall,-1 ) [import]uid: 75779 topic_id: 31381 reply_id: 125452[/import]