This is a basic tutorial to create a tween animation via programming in actionscript 3.0.
To start with,
1) Open a new Flash Document(AS3)
2) Click on a key frame and paste the following actionscript 3.0 code
3) Publish the movie to see the animation
// Importing classes from fl package must be done explicitly
import fl.transitions.Tween;
import fl.transitions.easing.*;
// Declare variables for the tween movement. These could just as easily be local below.
var moveBackX:Tween;
var moveBackY:Tween;
var moveRound:Tween;
// Create a holder and a draggable box
var dragger:Sprite = new Sprite();
var holder:Sprite = new Sprite();
//draw the rectangle which is to be dragged
dragger.graphics.lineStyle(1,0);
dragger.graphics.beginFill(0xCC0033);
dragger.graphics.drawRoundRect(-50,-25,100,50,15,15);
dragger.graphics.endFill();
dragger.x = 300;
dragger.y = 150;
//draw the holder for drag object
holder.graphics.lineStyle(1,0)
holder.graphics.beginFill(0xFFFFFF);
holder.graphics.drawRoundRect(-51,-26,100,50,15,15);
holder.graphics.endFill();
holder.x = 300;
holder.y = 150;
//Display the graphics on the stage
stage.addChild(holder)
stage.addChild(dragger)
/*
Add listeners so that a "mouse down" on the box starts the drag but a "mouse up" anywhere
stops the dragging.
*/
dragger.addEventListener(MouseEvent.MOUSE_DOWN,goDrag)
stage.addEventListener(MouseEvent.MOUSE_UP,goBack)
// Functions
// goDrag
function goDrag(evt:MouseEvent):void{
dragger.startDrag();
dragger.filters = [new DropShadowFilter()];
}
// goBack
function goBack(evt:MouseEvent):void {
dragger.stopDrag()
dragger.filters = []
moveBackX = new Tween(dragger, "x", Strong.easeOut, dragger.x, holder.x, 0.5, true);
moveBackY = new Tween(dragger, "y", Strong.easeOut, dragger.y, holder.y, 0.5, true);
moveRound = new Tween(dragger, "rotation", Strong.easeIn, 0, 180, 0.5, true);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment