2

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/

sollniss
  • 1,895
  • 2
  • 19
  • 36
  • Doesn't help. I can even click objects which only contain a `stop();` and the next frame of the scene still gets activated. It's hard to explain because I just started flash today. – sollniss Apr 29 '13 at 17:35
  • I found the mistake. I was a missing object reference in my title screen. – sollniss Apr 29 '13 at 18:32
  • @sollniss - See my answer for your mistake. (in addition to your object reference missing) – BadFeelingAboutThis May 06 '13 at 23:14

2 Answers2

0

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();
}
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • I had it like this before, but I would always run into a `Symbol 'movKey', Layer 'Layer 1', Frame 1, Line 3 1120: Access of undefined property key.`. If I use `MovieClip(root).key.addEventListener(MouseEvent.CLICK, CollectKey);` it doesn't do anything to my problem. – sollniss Apr 29 '13 at 17:50
  • Also, you can remove all the `MovieClip(root)` stuff, since all your code is run on the root timeline anyway. – BadFeelingAboutThis Apr 29 '13 at 18:38
0

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.