Event.target.problem

Hi everyone,

I need your help again. I’ve a group of items, each of them have an “addEventListener” created through a for cycle. When the user clicks one of them, the related eventListener should be removed.

I suppose I should use an event.target.something to remove the right eventListener but I don’t know how could I do that.

Any ideas about?

Thanks a lot for your help =)

To achieve the same result you could have a boolean flag variable for each item called tapped. Let’s say your items created in the for loop are newRect’s with the respective names myRectangle[i]. In the loop you would set myRectangle[i].tapped=false. When the eventListener function is called, set event.target.tapped to true if its false and continue performing whatever operation the function is supposed to handle when called. If event.target.tapped is already true when its called, just have the function return immediately without doing anything.

I’m not sure if I understand your question right, but if you just want to remove an object touch/tap listener (or any other listener on the object) when the object is touched it’s pretty easy.

local function touchListener(event) event.target:removeEventListener("touch", touchListener) end local object = display.newRect(0, 0, 10, 10) object:addEventListener("touch", touchListener)

Thank you both guys, I’ve just tried torbenratzlaff’s solution and it works absolutely fine =)

Thank you very much!

To achieve the same result you could have a boolean flag variable for each item called tapped. Let’s say your items created in the for loop are newRect’s with the respective names myRectangle[i]. In the loop you would set myRectangle[i].tapped=false. When the eventListener function is called, set event.target.tapped to true if its false and continue performing whatever operation the function is supposed to handle when called. If event.target.tapped is already true when its called, just have the function return immediately without doing anything.

I’m not sure if I understand your question right, but if you just want to remove an object touch/tap listener (or any other listener on the object) when the object is touched it’s pretty easy.

local function touchListener(event) event.target:removeEventListener("touch", touchListener) end local object = display.newRect(0, 0, 10, 10) object:addEventListener("touch", touchListener)

Thank you both guys, I’ve just tried torbenratzlaff’s solution and it works absolutely fine =)

Thank you very much!