Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top