jeudi 25 juin 2015

ActionScript3: removeEventListener with function parameter

how can i removeVentListener from movieclip in actionsctip? 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 wto movieClips on the stage , colorChange_mc has two eventListeners 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.

Aucun commentaire:

Enregistrer un commentaire