Not sure what I’m doing wrong here.
Basically, I’ve created a grid layout of rectangles using a for loop.
[lua]for i = 1, 10 do
local myRect = display.newRect(0, 0, 20, 20)
…
end[/lua]
The layout code I’m using works perfectly well, however, I want to register a touch listener on each of the rectangles. I been trying to do this within the for loop using something like:
[lua]myRect:addEventListener(“tap”, goToFunction)[/lua]
When I attempt to run the code with the above listener code within the for loop, I get a Runtime Error:
Runtime error: assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
Is this because the rectangle is always named ‘myRect’ and it’s attempting to assign the listener to that object name every time it loops? If so, how would I go about changing the name on each loop (myRect1, myRect2, etc)?
Many thanks
[import]uid: 74503 topic_id: 21207 reply_id: 321207[/import]