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

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