Timeline Button Instance - addEventListener scoping problem

Hi everyone,

just a small problem I encountered and would be great if we can get a good explanation on why this is happening.

I have:
a button: btn
inside a movie clip: mc

the btn is animated on the mc timeline.

frames:

  1. this is my initial frame with stop();

2.this is when btn plays the first animation

5: stop()

6:empty keyframe

  1. this is when the btn plays the second animation

    10.gotoAndStop(1)

pls check below:

now here’s the code:


stop();
import flash.events.MouseEvent;
var nClicks:Number = 0;

mc.btn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void
{
	if(nClicks == 0){
		mc.gotoAndPlay("play");
		nClicks ++;
	}else{
		mc.gotoAndPlay("back");
		nClicks = 0;
	}
}

don’t worry abt the code much.

The first scenario “not working”, the clip plays animation one on the first click, then plays animation 2 on the second click, then at frame 10. gotoAndStop(1) and then it stops playing, as if
onClick() doesn’t exist anymore.

but all this works fine in “working” scenario, where all i did is deleting that empty keyframe in between.

just for the curiosity, plus because i used to organize my timeline with those empty keyframes, can someone please explain why is this happening?

What is this empty keyframe doing to the btn instance?

thanks