//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
Thursday, October 25, 2012
Bound Function AKA CallBacks AS3
//Another weird AS3 Syntax thing I did not know was possible:
private function takeCallback(boundFunction:Function):void
{
trace("calling boundFunction / callback");
boundFunction();
}//takeCallback
//Call Function and pass it an inlined function.
takeCallback( function():void { trace("Function Speaking") } );
Wednesday, October 24, 2012
Breaking Out of Non-Looping Statements:
notAloop:
{
trace("hello 1");
break notAloop;
trace("hello 2");
trace("hello 3");
}
trace("parenEnd");
do {
trace ("do this once.");
break;
trace ("don't do this.");
}while ( false );
//output:
/*
hello 1
parenEnd
do this once.
*/
A few new cool things I found I can do with actionScript syntax.
Subscribe to:
Comments (Atom)