actionscript
AS3 Random Star Field Animation
This simple function creates star field animation. You need MovieClip in your library with 'star' class linkage. If stars are not your thing, feel free to try it with any other image you make.
code ::
*_*
code ::
import flash.events.Event;
import flash.events.MouseEvent;
function starField():void {
var i:uint = 0;
while (i < 30) {
var a:star = new star();
a.x = Math.random()*400;
a.y = Math.random()*260;
var size:Number = Math.random()*40+20;
a.width = a.height = size;
a.addEventListener(Event.ADDED_TO_STAGE, getSpeed);
function getSpeed(evt:Event):void
{
evt.target.speed = Math.random()*20-10;
}
a.addEventListener(Event.ENTER_FRAME, onFrame);
function onFrame(evt:Event):void
{
evt.target.rotation += evt.target.speed;
}
addChild(a);
i++;
}
}
starField();
addEventListener(MouseEvent.MOUSE_UP, onup);
function onup(evt:MouseEvent):void
{
while(this.numChildren > 0) {
this.removeChildAt(0);
}
starField();
}
*_*

Post a Comment
0 Comments
Thanks for sharing your thoughts !