2011-04-12 24 views
0

如何使用ActionScript的事件偵聽器傳遞參數?如何在addEventListener中傳遞參數(動作腳本)

我有代碼,如下所示,它創建一個標籤,我想,當點擊標籤時,它應該傳遞與該標籤相關的工具提示。

這就是我要怎樣做:

public function create_folderpath():void 
{ 
    for(var i:int = 0; i < fm_model.absolute_path_ac.length; i++) 
    { 
     var absolutePathToolTip:String = new String; 
     for(var j:int = 0; j <= i; j++) 
     {        
      absolutePathToolTip += fm_model.absolute_path_ac[j].path.toString() + '/'; 
     } 

     var textItem:Label = new Label(); 
     textItem.data = absolutePathToolTip;       
     textItem.toolTip = absolutePathToolTip; 
     textItem.text = fm_model.absolute_path_ac[i].path.toString() + ' /'; 
     textItem.addEventListener(MouseEvent.CLICK, testing)        
     directoryPathHBox.addChild(textItem); 
    } 
} 

public function testing(e:MouseEvent) 
    var direcoryLabel:Label = e.target as Label; 
    Alert.show(direcoryLabel.data +""); 
} 

這是不行的,況且我得到任何錯誤。

請幫我解決這個問題。

在此先感謝 Zeeshan

回答

1

嘗試使用「currentTarget當前」,而不是「目標」:

var direcoryLabel:Label = e.currentTarget as Label; 
Alert.show(direcoryLabel.data +""); 

而且一定要添加一絲聽衆,要知道,如果它被稱爲或不。