How to call "this" from an anonymous method?(flex, as)
This is my code:
public function setPaneContent(names : Array, parent : AbstractPane) : void  {
//....
 okBut开发者_开发知识库ton.addEventListener(MouseEvent.CLICK, function okMouseClickHandler(e : Event) : void {
                parent.addNewPane(valuesPane, parent);
                    PopUpManager.removePopUp(/*need to put "this"*/);
                });
 //.....
}
When i call PopUpManager.removePopUp(/*need to put "this"*/);, i need to make a reference at the object that contains this method(this). 
So my question is: "Is it possible to make a reference at 'this' keyword within an anonymous method?"
store this to some variable: _this = this in the constructor, use _this. (it works in javascript)
You don't have to, you can call another function
public function setPaneContent(names : Array, parent : AbstractPane) : void  
{
     okButton.addEventListener(MouseEvent.CLICK, 
                    function okMouseClickHandler(e : Event) :void 
         {
            parent.addNewPane(valuesPane, parent); 
            // call the remove function where you can reference "this"
            remove();
         });
         //.....
}
private function remove():void
{ 
    PopUpManager.removePopUp(this);
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论