Generic events and additional parameters in Actionscript 3.0?

后端 未结 3 1399
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 18:23

Assuming the following pattern:

someObjectInstance.addEventListener(MyDisplayObject.EVENT_CONSTANT, _handleMyEvent);


private function _handleMyEvent( event:Eve         


        
3条回答
  •  野的像风
    2021-01-25 19:03

    There is a way of passing custom data to the handler method without creating a custom event.

    private function test() {
        var data : SomeObject = new SomeObject;
        var a:SomeEventDispatcher = new SomeEventDispatcher();
        a.addEventListener(Event.COMPLETE, handle(data));   
        a.dispatchCompleteEvent();
    }
    
    private function handle(data : SomeObject) : Function {
        return function(e : Event) : void {
           IEventDispatcher(e.target).removeEventListener(Event.COMPLETE, arguments.callee);
           trace(e + ", " + data);
        };
    }
    

提交回复
热议问题