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

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