0

I am trying to add eventListener for each of the balls i created in the screen. I create the balls with for loop and then assigned them to an array. It worked well so far. However, when i tried to add eventListener for each ball in the loop, it gave me phase nil value error. Can you please help me figure it out? Thanks

Here is my code:

function ballListener(event) if(phase.event=="ended") then target.event.isvisible=false end end for i=1,10,1 do a=display.newImage("ball.jpg") a.x=math.random(10,200) a.y=math.random(10,200) a:addEventListener("touch",ballListener) table.insert(balls,a) end 
1
  • can you post the full text of the error you're receiving? Commented Jun 22, 2012 at 13:45

1 Answer 1

1

For starters, some things in your ballListener function are backwards. It should be "event.phase" and "event.target" because "phase" and "target" are properties of the event. Also isvisible should be isVisible. The end result should look like this:

function ballListener(event) if(event.phase=="ended") then event.target.isVisible=false end end 

I haven't tested the code, so there may be other issues I've missed.

Check out the Corona API.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.