how can i remove EventListener
from MovieClip
in actionscript? Below is my sample code.
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
var color: ColorTransform = new ColorTransform();
color.color = 0x00CC66;
colorChange_mc.buttonMode = true;
colorChange_mc.addEventListener(MouseEvent.MOUSE_OVER, changeColor(color));
colorChange_mc.addEventListener(MouseEvent.MOUSE_OUT, changeColorToNormal);
function changeColor(color: ColorTransform): Function {
return function (e: MouseEvent): void {
colorChange_mc.transform.colorTransform = color;
}
}
function changeColorToNormal(e: MouseEvent): void {
var color: ColorTransform = new ColorTransform();
color.color = 0x000033;
colorChange_mc.transform.colorTransform = color;
}
changer_mc.buttonMode = true;
changer_mc.addEventListener(MouseEvent.MOUSE_DOWN, removeEvent);
function removeEvent(e: MouseEvent): void {
colorChange_mc.removeEventListener(MouseEvent.MOUSE_OVER, changeColor(color));
}
I created two MovieClip
s on the stage
, colorChange_mc has two EventListener
s one for mouseDown
and one for mouseOut
. When change_mc button is pressed I want to remove one of the EventListener
. I was able to remove EventListener
without passing parameter to changeColor function. But in my real class this parameter plays crucial role.
Use a class-var instead - one you have already in your code. To keep straight I created a second
ColorTransform
as a class-var -normalColor
Greetings.