Skip to content

AS3 Code Shorthand

These are just some AS3 code short hand examples.

// if( Boolean ){ A } else { B };
( Boolean ) ? A : B ;

// still checking Boolean, also Functions in an Array.
var str = "Hello";
str is String ? [ A(), B()] : [ B(), A() ];
function A():void{ trace( "A" ) }
function B():void{ trace( "B" ) }

// odd or even?
Boolean = (( Number % 2 ) == 0); // bitwise
Boolean = (( Number & 1 ) == 0); // binary 

// trace coolness using "," instead of "+"
trace( "A" , "B" );

// ok, this isn't short hand, but good to keep around
try { Function() }
catch(error:Error) { trace( "\t ! " , error.message ) }

// simple rotation around the stage from center
var _rot:Number = Math.round( (Math.atan2( mouseY - y, mouseX - x)) * (180 / Math.PI) ) * 6;
obj.rotation = rot;

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*