Skip to main content
Inspiring
May 29, 2013
Answered

removeEventListener won't work?

  • May 29, 2013
  • 1 reply
  • 1155 views

Hello. I am using Adobe Flash CS6.

Right now I put a AS on root that does removeEventListener to remove event listener inside  a movie clip "mcA", but it can not remove the event listener. so I put removeEventListener inside mcA and it works fine. Why? I can not remove event listener from root so if I need to remove event listener inside movie clips I should write removeEventListener   not on root but inside them?

This topic has been closed for replies.
Correct answer kglad

because test is not on the root timeline.  use:

stage.addEventListener (MouseEvent.CLICK,Remove_Event);

function  Remove_Event(event:MouseEvent):void

{

mcA.mcB.removeEventListener (MouseEvent.CLICK,mcA.test);

}

//And I put this AS inside mcA.

mcB.addEventListener (MouseEvent.CLICK,test);

function  test(e:Event):void{

mcB.rotation +=5;

}

1 reply

kglad
Community Expert
Community Expert
May 29, 2013

you need to remove the event listener from the correct scope after the listener has been added (and make sure it's not re-added).

so, if you used,

addEventListener("someevent",somefunction);

inside mcA and mcA is on the root timeline, you would use the following from the root timeline AFTER mcA exists and AFTER the above listener is added,

mcA.removeEventListener("someevent",somefunction);

Inspiring
May 29, 2013

I put a movie clip "mcA",which has a movie clip "mcB" inside, on root

and put this AS on root.

stage.addEventListener (MouseEvent.CLICK,Remove_Event);

function  Remove_Event(event:MouseEvent):void

{

mcA.mcB.removeEventListener (MouseEvent.CLICK,test);

}

And I put this AS inside mcA.

mcB.addEventListener (MouseEvent.CLICK,test);

function  test(e:Event):void{

mcB.rotation +=5;

}

And I get this error message.

1120: Access of undefined property test.

I can not access function "test" from root. Why?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 29, 2013

because test is not on the root timeline.  use:

stage.addEventListener (MouseEvent.CLICK,Remove_Event);

function  Remove_Event(event:MouseEvent):void

{

mcA.mcB.removeEventListener (MouseEvent.CLICK,mcA.test);

}

//And I put this AS inside mcA.

mcB.addEventListener (MouseEvent.CLICK,test);

function  test(e:Event):void{

mcB.rotation +=5;

}