Skip to main content
June 28, 2010
Answered

addEventListener function references child in movieclip. how do i stop this?

  • June 28, 2010
  • 1 reply
  • 1070 views

I built a custom designed checkBox. The movieclip is in the libary and dragged onto the timeline of my .swf. I'm using CS4 & AS3. I'm using procedural AS3 instead of OO AS3.

The checkbox movieclip has a child movieclip inside of it so I can apply a drop shadow filter to some of the graphics .

When I put an eventlistener on the custom checkbox it works fine but when I try to reference the checkbox movieclip inside the eventlistener function, the event.target.name is referring to the child movieclip (just a graphic with a drop shadow filter).

From my reading it looks like the function propogates down to the child movieclip but I don't want it to do that.

How do I

A.  reference the parent movieclip?

     or

B. stop the eventlistener from propogating down to the child movieclip?

I tried using stopPropagation(); but it didn't stop the function event.target.name from trickling down to the child movieclip.

Here's what AS3 looks like.

The trace statement displays "step3_mc.cbEmail_mc.instance25"  instead of what I need "step3_mc.cbEmail_mc"

step3_mc.cbEmail_mc.addEventListener(MouseEvent.CLICK, fnc_cbClick);
step3_mc.cbAgree_mc.addEventListener(MouseEvent.CLICK, fnc_cbClick);

function fnc_cbClick(event:MouseEvent):void  {

    trace ("fnc_cbClick: " + event.target.name + " " + event.target.currentFrame  );

    if (event.target.currentFrame < 3 ) { event.target.gotoAndPlay("cbOn"); } else { event.target.gotoAndPlay("cbOff"); }
}

This topic has been closed for replies.
Correct answer VarioPegged

Use event.currentTarget.name to get the name of the instance you want (that's the instance that the event listener is assigned to). If you use event.target.name, the name of the instance where the click originated will be traced, which may or may not be the one you intended.

ts

1 reply

VarioPeggedCorrect answer
Inspiring
June 28, 2010

Use event.currentTarget.name to get the name of the instance you want (that's the instance that the event listener is assigned to). If you use event.target.name, the name of the instance where the click originated will be traced, which may or may not be the one you intended.

ts

June 28, 2010

That worked.

Thanks for the response VarioPegged.