i find addeventlistener
method bit limited. use version of it, made me. insert parameter tell if dispatched event can auto removed, avoid me have write in everywhere:
obj.addeventlistener(click, function onclick(e:event):void { obj.removeeventlistener(click, onclick); // <--- want avoid });
then:
obj.addeventlistener(click, function onclick(e:event):void { // no need anymore. }, true); // <--- see
what approach can take in order reach that?
you can intercept addeventlistener
method call using override closures:
override public function addeventlistener(type:string, listener:function, usecapture:boolean = false, priority:int = 0, useweakreference:boolean = false):void { var self = this; var weaklistener:function = function(e) { self.removeeventlistener(type, weaklistener); listener(e); } super.addeventlistener(type, weaklistener, usecapture, priority, useweakreference); }
Comments
Post a Comment