Super() Explained
November 20, 2008 by jared
The super() class is used to simply call on the particular class from which you are extending from.
In this example we have 3 files:
SuperExample.fla –> Which uses ChildClass.as as the document class.
ChildClass.as –> Our child class which extends from ParentClass.as
ParentClass.as –> Our parent class, which extends from GrandParentClass.as
GrandParentClass.as –> Our grand parent class, which extends from a Sprite class
In ParentClass.as we have a constructor which accepts a String. We’ll use this later on in ChildClass.as . Inside the constructor we have two trace statements, one tracing from the ParentClass itself, and one to accept a string as a parameter.
In ChildClass.as we can see one line in the constructor,
super("Hello from the ChildClass");
Where super is actually calling on the ParentClass constructor, passing in a string “Hello from the ChildClass”, which in turned is “supered” to its extended class GrandParentClass.as
Click here to download the files in this example.
addEventListener using a for loop
November 12, 2008 by jared
Instead of using
btn0.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn1.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn2.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn3.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn4.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn5.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn6.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn7.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn8.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn9.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn10.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn11.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn12.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
btn13.addEventListener(MouseEvent.MOUSE_OVER, doSomething);
You could use this
for (var i:uint = 0; i < 14; i++)
this["btn"+i].addEventListener(MouseEvent.MOUSE_OVER, doSomething);
Click here to download sample file addEventListener.fla
AS3 If statement syntax shortcut
November 11, 2008 by jared
var v : Boolean = true;
var i : int;
v ? i = 0 : i = 1;
Is the same as
var v : Boolean = true;
var i : int;
if (v)
i = 0;
else
i = 1;


