Question

I have a scene with a few objects as movieclips which can be clicked one at a time. What happens is that I'm able to click every object and on click the scene switches to the next frame.

How do I change that?

Basically I have a key and a door, both movieclips. You can collect the key, it disappears and after that you are able to click the door to open it. What actually happens is you are both able to click the key and the door. When you click the key, it's working as intended, but when you click the door, the key still disappears. This is much more annoying with more than 2 objects.

code for the key:

addEventListener(MouseEvent.CLICK, CollectKey);

function CollectKey(event: MouseEvent): void
{
    this.visible = false;
    // door
    MovieClip(root).door.addEventListener(MouseEvent.CLICK, MovieClip(root).FinishGame);
}

code for the door:

stop();

function FinishGame(event: MouseEvent): void
{
    if(MovieClip(root).currentFrame == 4)
    {
        nextFrame();
    }
}

http://www.wuala.com/sollniss/stuff/Untitled-2.swf/
http://www.wuala.com/sollniss/stuff/Untitled-2.fla/

Was it helpful?

Solution

EDIT

After looking at your .fla, I can see your issue:

On your first frame, you have the following script:

stop();

addEventListener(MouseEvent.CLICK, StartGame);

function StartGame(event: MouseEvent): void
{
    nextFrame();
}

You likely aren't aware that the mouse click listener you add there, doesn't go away until you tell it to (even if the frame changes). That's why every click calls next frame.

To remedy this, simply remove the listening before you move on to the next frame:

function StartGame(event: MouseEvent): void
{
    removeEventListener(MouseEvent.CLICK, StartGame);
    nextFrame();
}

OTHER TIPS

And, may be that only visible false is not enough, you also need to set enabled = false and mouseEnabled = false for the key element, because without it, it will keep hearing the click event.

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