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

AS3 Button Component: Create a toggle button and change color

Create a button component on your stage.
Give it an instance name of bRed.

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

Actionscript:

//Sets the text at runtime
tMessages.text=" Pick your favorite color" ;

//Labels the button at runtime
bRed.label = " Turn Red" ;
//sets the toggle mode
bRed.toggle = true;

//Click listener
bRed.addEventListener(MouseEvent.CLICK, fRed);

function fRed(event:MouseEvent):void {
trace(event.target.selected);
//Checks to see if button is toggled down
if (event.target.selected==true) {
//changes the text color
tMessages.textColor = 0xFF0000;
//changes the button label
event.target.label = " Turn White" ;
}else{
tMessages.textColor = 0xFFFFFF;
event.target.label = " Turn Red" ;
}
}

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

Target an Event: Have a function detect which target is triggered

Create two button movieclips on your stage.
Give one an instance name of bButton1 and the other bButton2.

Add this code to your actions:

bButton1.addEventListener(MouseEvent.ROLL_OVER,fOver);
bButton2.addEventListener(MouseEvent.ROLL_OVER,fOver);

function fOver(evt:Event):void {
tText.text="Over "+evt.target.name;
trace("Over "+evt.target.name);
}

EXAMPLE:

Get Adobe Flash player

addEventListener: Basic Button

There are many ways to create buttons. Here is an example of a simple EventListenter:

//Activates the "fDown"function
bButton.addEventListener(MouseEvent.MOUSE_DOWN, fDown);
//Activates the "fUp"function
bButton.addEventListener(MouseEvent.MOUSE_UP, fUp);

//activated by "MOUSE_DOWN" listener
function fDown(evt:MouseEvent):void {
//changes the message to "Mouse Down"
tMessage.text="Mouse Down";
}

//activated by "MOUSE_UP" listener
function fUp(evt:MouseEvent):void {
//Clears the message
tMessage.text="";
}

Example

Get Adobe Flash player