(roll your mouse over the image above).

In this eSeminar I show how to do all your animation using ActionScript 3.  Why?  Well, some things just can’t be done in the timeline.  For instance, if you want a movieclip to follow the mouse.  Or you want to animate to an undefined location that’s not known until runtime (where the user clicks).  These are just some of the cases where you’d want to us ActionScript to animate.  Below is the code or you can also download the source files here.

/******************************************
MouseEvents
******************************************/
skull_mc.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
function onMouseOver(event:Event):void {
skull_mc.nextFrame();
}
skull_mc.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
function onMouseOut(event:Event):void {
skull_mc.prevFrame();
}
/******************************************
ENTER_FRAME event
******************************************/
skull_mc.addEventListener(Event.ENTER_FRAME, moveSkull);
function moveSkull(event:Event):void {
skull_mc.x += (mouseX - skull_mc.x) / 10;
skull_mc.y += (mouseY - skull_mc.y) / 10;
}
/******************************************
Timer events
******************************************/
var myWingTimer:Timer=new Timer(10);
myWingTimer.start();
myWingTimer.addEventListener(TimerEvent.TIMER, moveWings);
function moveWings(myevent:TimerEvent):void {
wings_mc.x += (mouseX - wings_mc.x) / 10;
wings_mc.y += (mouseY - wings_mc.y) / 10;
}
var myBkgdTimer:Timer=new Timer(10);
myBkgdTimer.start();
myBkgdTimer.addEventListener(TimerEvent.TIMER, moveBkgdCircle);
function moveBkgdCircle(myevent:TimerEvent):void {
bkgd_mc.x += (mouseX - bkgd_mc.x) / 50;
bkgd_mc.y += (mouseY - bkgd_mc.y) / 50;
}
/******************************************
Tween Class
******************************************/
import fl.transitions.*;
import fl.transitions.easing.*;

skull_mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:Event):void {
skull_mc.removeEventListener(Event.ENTER_FRAME, moveSkull);
myWingTimer.stop();
var skullYTween:Tween=new Tween(skull_mc, "y", Bounce.easeInOut, skull_mc.y, 40, 1, true);
var skullXTween:Tween=new Tween(skull_mc, "x", Bounce.easeInOut, skull_mc.x, 385, 1, true);
var wingsYTween:Tween=new Tween(wings_mc, "y", Elastic.easeInOut, wings_mc.y, 40, 1, true);
var wingsXTween:Tween=new Tween(wings_mc, "x", Elastic.easeInOut, wings_mc.x, 385, 1, true);
skullYTween.addEventListener(TweenEvent.MOTION_FINISH, skullYTweenFinished);
}
//When the tween is finished then show the menu
function skullYTweenFinished(e:TweenEvent) {
menu_mc.visible = true;
}

Comments are closed.