Friday, May 16, 2014

Mouse tail in flash as3.0

Mouse tail in as3.0




var tailLength:uint = 10;
var spacing = 25;
var speed = 3;
var mc:MovieClip;
var clips:Array = [];
for (var i:uint = 0; i<tailLength; i++)
{
    mc= new Ball();
 
    mc.id = i;
    clips.push(mc);
 
    addChild(clips[i]);
    if (i>0){
        clips[i].addEventListener(Event.ENTER_FRAME, MoveOtherBalls);
    }
    else
    {
        clips[i].addEventListener(Event.ENTER_FRAME, MoveFirstBall);
    }
}
function MoveFirstBall(e:Event)
{
    var clip:MovieClip = MovieClip(e.currentTarget);
    clip.x += (this.mouseX-clip.lastX)/speed;
    clip.y += (this.mouseY-clip.lastY)/speed;
    clip.lastX = clip.x;
    clip.lastY = clip.y;
}
function MoveOtherBalls(e:Event)
{
    var clip:MovieClip = MovieClip(e.currentTarget);
    clip.x += ((clips[clip.id -1].x-clip.lastX)/speed);
    clip.y += ((clips[clip.id -1].y-clip.lastY)/speed)+8;
    clip.lastX = clip.x;
    clip.lastY = clip.y;
}

The above programe is developed in flash as3.0.

How to run above programe in flash.?

Follow below simple 10steps.

1). First draw a shape and convert into movieclip by pressing F8 key.
2). Choose movieclip in dropdown.
3). Make sure the Registration point in middle.
4). And tick mark "Export for actionscript".
5). In class field enter "Ball" then click ok.
6). Then delete the ball from stage. This object will be there in library. So don't worry about to delete from stage.

7). Then click first frame in the timeline and press F9 key to open actionscript pannel.
8). And copy above programe and paste it.
9). To run press Ctrl+Enter.
10). Move mouse, the 10 ball are move like a tail by, one by one.
Enjoy it :)

By
Vickybees