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 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).

Rotate a MovieClip with AS3

Create four Buttons on your stage.
Give the first an instance name of bSlow.
Give the second an instance name of bStart.
Give the third an instance name of bStop.
Give the last an instance name of bFast.

Create a MovieClip of a happy face on the stage.
Give it an instance name of mcFace.

Actionscript:

//variable to hold the speed
var speed:Number=.1;

bSlow.addEventListener(MouseEvent.CLICK, fSlow);
bStop.addEventListener(MouseEvent.CLICK, fStop);
bStart.addEventListener(MouseEvent.CLICK, fStart);
bFast.addEventListener(MouseEvent.CLICK, fFast);

function fSlow(event:MouseEvent):void {
speed=speed-1;
mcFace.rotation+=speed;
}

function fStop(event:MouseEvent):void {
speed=0;
mcFace.rotation+=speed;
}

function fStart(event:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, fSpin);
speed=1;
mcFace.rotation+=speed;
}

function fFast(event:Event):void {
speed=speed+1;
mcFace.rotation+=speed;

}

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

Example:

Get Adobe Flash player

Loops: Create a "for loop" in AS3

Create a button movieclip on your stage.
Give it an instance name of bStart.

Create an input text box on your stage.
Give it an instance name of itSteps.

Create a dynamic text box on your stage.
Give it an instance name of tMessages.

Actionscript:

bStart.addEventListener(MouseEvent.CLICK, fLoop);

itSteps.restrict = "0-9";
itSteps.maxChars = 3;

function fLoop(event:MouseEvent):void {
tMessages.text="";
var vString:String = itSteps.text;
var vExample:Number = Number(vString);
for (var i:Number=0; i < vExample; i++) { tMessages.appendText([i]+", "); } }

Example:

Get Adobe Flash player

URLRequest: Make an Email link using AS3 (Option 2)

Create a button movieclip on your stage.
Give it an instance name of bEmail.

Actionscript:

bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);

function fEmailClick(event:MouseEvent):void {
navigateToURL(new URLRequest("mailto:dankempton@gmail.com"),"_self" );
}

Example:

Get Adobe Flash player

URLRequest: Make an Email link using AS3 (Option 1)

Create a button movieclip on your stage.
Give it an instance name of bEmail.

Actionscript:

var vEmail:URLRequest = new URLRequest(" mailto:dankempton@gmail.com" );

bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);

function fEmailClick(event:MouseEvent):void {
navigateToURL(vEmail," _self" ) ;
}

Example:

Get Adobe Flash player