2014-01-22 38 views
0

這是我的ActionScript:ActionScript 3 - 找出哪個MovieClip稱爲事件偵聽器?

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轉爲橙色(0xCC6600)。有沒有辦法讓我做到這一點?

回答

2

你要看一看該事件的target

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

根據displayObject的觸發事件組成,你可能需要使用currentTarget代替。

documentation

The object that is actively processing the Event object with an event listener. For example, if a user clicks an OK button, the current target could be the node containing that button or one of its ancestors that has registered an event listener for that event.

+0

嗯,當我做到這一點,它說「類型錯誤:錯誤#1010:期限是不確定的,沒有屬性。在MainTimeline/optioniContainerOver()' – user2817200

+0

好吧,而不是evt.target,我將它改爲evt.currentTarget,它的工作..你可以改變你的答案,我會把它標記爲答案..這是一個很好的解釋爲什麼它沒有與目標一起工作,但與currentTarget合作,供將來參考,如果其他人有這個相同的問題:http://stackoverflow.com/questions/5921413/difference-between-e-target-and-e-currenttarget – user2817200