ActionScript 3 - 找出哪个MovieClip称为事件监听器?

时间:2014-01-22 14:13:39

标签: arrays actionscript-3 flash mouseevent

这是我的ActionScript:

var containers = [
              option1Container,
              option2Container,
              option3Container,
              option4Container
             ];

for (var i = 0; i < containers.length; i ++) {
    containers[i].BlueBox.filters = [myShadowFilter]; 
   //BlueBox is an object inside the container. The above line adds a DropShadow to BlueBox

    containers[i].addEventListener(MouseEvent.MOUSE_OVER, optioniContainerOver);
    //give each item in the array the same mouse over and mouse out listener

    containers[i].addEventListener(MouseEvent.MOUSE_OUT, optioniContainerOut);
}

//create a color transform called optionOver
var optionOver:ColorTransform = new ColorTransform();
optionOver.color = 0xCC6600;


function optioniContainerOver(evt:Event):void {
containers[i].BlueBox.transform.colorTransform = optionOver; //this doesn't work.
}

现在,正如您所看到的,我正在尝试使用名为optioniContainerOver的函数,只要容器数组中的movieclip悬停在上面,我希望只有特定的MovieClip变为橙色(0xCC6600)。有没有办法让我这样做?

1 个答案:

答案 0 :(得分:2)

您需要查看活动的target

function optioniContainerOver(evt:Event):void {
    evt.target.BlueBox.transform.colorTransform = optionOver;
}

根据displayObject触发事件的构成,您可能需要使用currentTarget

来自documentation

  

使用事件侦听器主动处理Event对象的对象。例如,如果用户单击“确定”按钮,则当前目标可以是包含该按钮的节点或其已为该事件注册事件侦听器的其祖先之一。