addChild addEventListener array breakdown Buttons component Dynamic Text else email ENTER_FRAME event target for function habits if statement Input Text Instantiate KeyboardEvent keyCode label length loop mouseEnabled MouseEvent movieClips name Number operator position restrict rotation sprite stageHeight stageWidth strings text textColor toggle trace URLRequest variables visible while

AS3 Properties: Simple movieClip rotation

Create a movieClip on the stage.
Give the movieClip an instance name of "mcFace"

Actionscript:

addEventListener(Event.ENTER_FRAME, fSpin);

function fSpin(event:Event):void {
mcFace.rotation+=1;
}

Get Adobe Flash player

AS3 String Manipulation: Remove and replace with split and join

AS3 Instantiate: Load a MovieClip from the library with addChild

Create a movieClip on your stage and name it mcDot.
Delete the mcDot from your stage.
Open the library panel, right-click the mcDot clip then select properties:

addChildMenu

Under the "Linkage" category check "Export for ActionScript"
Give the class the name "Dot". Make sure it is capitalized.

addChildProperties

Actionscript:

var dot:Dot= new Dot;
addChild(dot);

dot.x=stage.stageWidth/2;
dot.y=stage.stageHeight/2;

Programming Habits: Add increment variation

Especially when building loops, you will need to add an increment to an existing operand or Number variable. There is a logical way to do this and a shorthand alternative using the "++" operator.

This:

i=i+1;

is the same as this:

i++;

AS3 Loops: Simple "while" loop

var i:Number= 0;

while (i < 5) {
trace([i]);
i = i+1;
}

AS3 Loops: Simple "for" loop

for (var i:Number=0; i < 5; i++) {
trace(i);
}

AS3 Arrays: Access objects inside an array

Add five button components to the stage.

Give first button an instance name of bButton1.
Give second button an instance name of bButton2.
Give third button an instance name of bButton3.
Give fourth button an instance name of bButton4.
Give last button an instance name of bButton5.

Actionscript:

var aButtons:Array = new Array (bButton1, bButton2, bButton3, bButton4, bButton5);

trace(aButtons);
//returns the contents of the array
trace(aButtons[1].name);
//trace the name of object in specific position in an array. Index position must be in brackets. This trace would return "bButton2".
trace(aButtons[1].label);
//trace the label of object in specific position in an array. Index position must be in brackets. This trace would return the label of your second button.
trace(aButtons.length);
//returns the length of the array. This trace would return "5"

AS3 Arrays: Access elements in a string array

//String array

Example

var aString:Array = new Array ("Name", "Address", "State", "Zip", "Phone");
trace(aString);
//returns the contents of the array
trace(aString[1]);
//trace the position of an object in an array. Index position must be in brackets. This trace would return "address".
trace(aString.length);
//returns the length of the array. This trace would return "5"

AS3 Arrays: Array breakdown

var testArray:Array=new Array("name","address","state","zip","country");
//Naming the array variable

var testArray:Array=new Array("name","address","state","zip","country");
//Datatyping the variable as an Array

var testArray:Array=new Array("name","address","state","zip","country");
//Setting up a new array

var testArray:Array=new Array("name","address","state","zip","country");
//contents of the array. Each item is assigned a numerical index starting with 0. The example above would be (0,1,2,3,4).

A Complex Clock for fun

Get Adobe Flash player