//Event Listener Trick using bracket notation: //Standard way:-------------------------------------------------------------------- public function addEventListeners():void { someObject_01.addEventListener(Event.ENTER_FRAME, someFunction_01); someObject_02.addEventListener(Event.ENTER_FRAME, someFunction_02); someObject_03.addEventListener(Event.ENTER_FRAME, someFunction_03); } public function removeEventListeners():void { someObject_01.removeEventListener(Event.ENTER_FRAME, someFunction_01); someObject_02.removeEventListener(Event.ENTER_FRAME, someFunction_02); someObject_03.removeEventListener(Event.ENTER_FRAME, someFunction_03); } //--------------------------------------------------------------------------------- //Using bracket notation----------------------------------------------------------- public function setEventListeners(add:Boolean):void { var XXX:String; if(add ){XXX = "addEventListener" }; if(!add){XXX = "removeEventListener"}; someObject_01[XXX](Event.ENTER_FRAME, someFunction_01); someObject_02[XXX](Event.ENTER_FRAME, someFunction_02); someObject_03[XXX](Event.ENTER_FRAME, someFunction_03); } //---------------------------------------------------------------------------------
Monday, October 29, 2012
Event Listener trick using bracket notation
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment