ActionScript Tutorial no 1

2009-02-18

So, you want to develop a cool “Mouse Trailer Dust Sparkle” effect as in here. This costs 1$. Here’s a tutorial which will tell you how to do it. I’ve accomplished it using a MovieClip with a small circle. You can just replace it with your own.  Here’s the code.

package
{
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.events.Event;

    public class trailer extends MovieClip
    {
        private function trail(e:MouseEvent):void
        {
            var trailMC:MovieClip=new MovieClip();
            trailMC.graphics.beginFill(0×000000);
            trailMC.graphics.drawCircle(stage.mouseX,stage.mouseY,5);
            trailMC.graphics.endFill();
            this.addChild(trailMC);
        }
        private function bring_it_down(e:Event):void
        {
            var Child:MovieClip;
            for(var i:int=0;i<this.numChildren;i++)
            {
                Child=MovieClip(this.getChildAt(i));
                if(Child.alpha<=0 || Child.y>=stage.height)
                    this.removeChild(Child);
                Child.alpha-=0.05;
                Child.y+=2;
            }
        }
        public function trailer():void
        {
            stage.addEventListener(MouseEvent.MOUSE_MOVE, trail);
            stage.addEventListener(Event.ENTER_FRAME, bring_it_down);
        }
    }
}