2011-04-12 25 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 +""); 

而且一定要添加一丝听众,要知道,如果它被称为或不。