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?
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;
}
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);
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?
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;
}
Copy link to clipboard
Copied
It works! Thank you.
Copy link to clipboard
Copied
you're welcome.