• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

removeEventListener won't work?

Explorer ,
May 28, 2013 May 28, 2013

Copy link to clipboard

Copied

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?

TOPICS
ActionScript

Views

922

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 29, 2013 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;

}

Votes

Translate

Translate
Community Expert ,
May 28, 2013 May 28, 2013

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 29, 2013 May 29, 2013

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2013 May 29, 2013

Copy link to clipboard

Copied

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 29, 2013 May 29, 2013

Copy link to clipboard

Copied

It works! Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2013 May 29, 2013

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines