0

I'm not even sure if this is a problem that can be solved through code. I have simple movie clips in an array that I'm trying to add click Event Listeners to, and I can change the buttonMode to true and add the event Listener, but only one of the movieclips actually shows the behavioral changes from the buttonMode and event Listener.

for(var d:int = 0; d < doors.length; d++)
{
    doors[d].buttonMode = true;
    doors[d].addEventListener(MouseEvent.CLICK, doorClick);

    trace(doors[d].buttonMode);
    trace(doors[d].hasEventListener(MouseEvent.CLICK));
}

all the traces return true, and I traced d and doors[d] to make sure that the problem wasn't with the array, but it isn't and only the door at index 1 works as intended. How can I find why the listeners aren't working?

user2956947
  • 239
  • 1
  • 2
  • 12

1 Answers1

0

Isolate your doors and loop. The code will work on its own without other elements. I've had this same problem before and it's usually because the invisible portion of another movieclip is overlaying the button objects.

If you're adding other MovieClips dynamically that may overlay the doors, locate the container movieclip of those objects and set its properties mouseEnabled and mouseChildren to false. The container and its child objects will no longer receive mouse clicks instead of your door movieclips.

The answer here clarified the issue for me:

https://stackoverflow.com/a/2686510/629407

Community
  • 1
  • 1
invisible squirrel
  • 2,968
  • 3
  • 25
  • 26
  • is there any way to trace what is intercepting the mouseEvent? I have dozens of layers and nothing is obviously intersecting the doors – user2956947 May 11 '14 at 23:52
  • stage.addEventListener(MouseEvent.CLICK, testClick); – invisible squirrel May 11 '14 at 23:59
  • In the testClick function, trace(event.target); – invisible squirrel May 12 '14 at 00:00
  • It's like magic. I've been using currentTarget all this time. Is there any reason I shouldn't change all of my currentTargets over to targets? – user2956947 May 12 '14 at 14:00
  • I usually use currentTarget because when I do someObject.addEventListener(), someObject is usually what I want to operate on in the function handler. If clicking someObject's children then event.target will refer to that child which may be useful http://stackoverflow.com/q/5921413 – invisible squirrel May 12 '14 at 21:13