Thursday, October 21, 2010

Make A Movie Clip Follow Mouse Clicks Using ActionScript 3

Flex Builder 4 Flash Video Mouse Events

Click on the stage and the ball will follow the mouse click.


The Code

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;

var xMovement:Tween;
var yMovement:Tween;

function Start():void
{
stage.addEventListener(MouseEvent.CLICK, moveToClick);
}

function moveToClick(event:MouseEvent):void
{

xMovement = new Tween(circle_mc,"x",Back.easeIn,circle_mc.x,mouseX,.7,true);
yMovement = new Tween(circle_mc,"y",Back.easeIn,circle_mc.y,mouseY,.7,true);
}

Start();

The fl.transitions.package

The fl.transitions.package contains classes that let you use ActionScript to create animation effects. You use the Tween and TransitionManager classes as the primary classes for customizing animation in ActionScript 3.0.

Blinds The Blinds class reveals the movie clip object by using appearing or disappearing rectangles.
Fade The Fade class fades the movie clip object in or out.
Fly The Fly class slides the movie clip object in from a specified direction.
Iris The Iris class reveals the movie clip object by using an animated mask of a square shape or a circle shape that zooms in or out.
Photo Makes the movie clip object appear or disappear like a photographic flash.
PixelDissolve The PixelDissolve class reveals reveals the movie clip object by using randomly appearing or disappearing rectangles in a checkerboard pattern.
Rotate The Rotate class rotates the movie clip object.
Squeeze The Squeeze class scales the movie clip object horizontally or vertically.
Transition The Transition class is the base class for all transition classes.
TransitionManager The TransitionManager class defines animation effects.
Tween The Tween class lets you use ActionScript to move, resize, and fade movie clips by specifying a property of the target movie clip to animate over a number of frames or seconds.
TweenEvent The TweenEvent class represents events that are broadcast by the fl.transitions.Tween class.
Wipe The Wipe class reveals or hides the movie clip object by using an animated mask of a shape that moves horizontally.
Zoom The Zoom class zooms the movie clip object in or out by scaling it in proportion.

 

ActionScript 3.0 Reference

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...