AddEventListener Question.

Can anyone tell me why this isn’t working? I get a assertion failed! error when my code reaches the line:
‘event.other:addEventListener (“sprite”, removePeg )’
everything up to that point works as desired, animation plays when
the ball collides with a peg. Static peg runs through animation, then Whammo!
Beuller… Beuller…

ball.collision = function(self,event)
 if(event.phase == "ended" ) then
if(event.other.type == "GreenPeg") then
 audio.setVolume(.3)
 audio.play(ApaddleHit)
 event.other:prepare("GreenRemove") 
 event.other:play("GreenRemove")
 event.other:addEventListener ("sprite", removePeg )
 end

 function removePeg(event)
 print(event.phase)
 if event.phase == "end" then
 local temp = event.target
 temp:removeSelf()
 temp.target = nil
 end
 end 

[import]uid: 7382 topic_id: 11836 reply_id: 311836[/import]

TIA [import]uid: 7382 topic_id: 11836 reply_id: 43094[/import]

i dont know if you can use "ball.collision = function… "

try to do this

ballColision = function()  
  
-- all your code here  
  
end  
ball.collision = ballColision  
ball:addEventListener( "collision", ball )  

maybe this works [import]uid: 23063 topic_id: 11836 reply_id: 43104[/import]

ball.collision = function(self,event)
did everything it was supposed to. The pointer to other makes the object the hit by the ball runs through it’s animation cycle. I suspect the issue is how I’m adding the event listner to the referenced object, but I don’t know.

[import]uid: 7382 topic_id: 11836 reply_id: 43118[/import]

Uh… Problem resolved. This function works as it should as is. I gave up and was working on something else, when I started getting what I thought was an unrelated error. Fixed that, and this works fine.
[import]uid: 7382 topic_id: 11836 reply_id: 43119[/import]