2012-05-11 15 views
0

我寫了一個循環,爲我的視圖中的所有圖像添加一個MouseEVENT.CLICK事件偵聽器。Flex:如何動畫我點擊過的目標?

(這部分工作)

var numChildren:int = PageScroll.numChildren; 

for (var i:int = 0; i < numChildren; i++) { 
    if(PageScroll.getChildAt(i) is Image) 
    { 
     PageScroll.getChildAt(i).addEventListener(MouseEvent.CLICK, onClick); 
    } 
} 

現在我想的onClick玩,我點擊了目標的動畫...

我不知道如何做到這一點,並能「找不到它通過谷歌....

protected function onClick(event:MouseEvent):void 
{ 
    maxSize.play(new Array(event.target), false); 
} 

(這部分不工作)

+2

使用'currentTarget'。另請注意,如果您使用Flex 4容器(如標籤所示),您可能應該使用'getElement'而不是'getChild'。如果這是一個圖像列表,你似乎正在重新發明輪子:「List」組件就是你需要的。 – RIAstar

回答

0

檢查這個代碼;這將幫助你...

<mx:Canvas id="can" width="500" height="500"> 
     <mx:Image source="indian cricket logo.png"/> 
</mx:Canvas> 
<mx:Resize id="resize" widthBy="50" heightBy="50" duration="500"/> 


protected function application1_creationCompleteHandler(event:FlexEvent):void 
    { 
     for (var i:int = 0; i< can.numChildren;i++){ 
      if(can.getChildAt(i) as Image){ 
         Image(can.getChildAt(i)).addEventListener(MouseEvent.CLICK,onMouseCLick,false,0,true); 
        } 
      } 

    } 

private function onMouseCLick(e:MouseEvent):void 
{ 
    resize.play([e.currentTarget]); 
}