开发者

How to pass argument in addEventListener (Action Script)

How do I pass arguments using ActionScript's event-listener?

I have code, as given below, which creates a label, and I want, when clicked on the label it should pass the toolTip associated with that label.

This is what I was trying to do:

public function create_folderpath():void
{
    for(var i:int = 0; i < fm_model.absolute_path_ac.length; i++)
    {   
        var absolutePathToolTip:String = new String;
开发者_JS百科        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 +"");
}

This does not work, nor do I get any errors.

Please, I need help with this.

Thanks in advance Zeeshan


Try to use "currentTarget" instead of "target":

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

And be sure to add a trace in the listener, to know for sure if it's called or not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜