In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Star Field

Just a star field!
Get Adobe Flash player
by butr0s 13 Apr 2009
// Just a star field!
package {
	import flash.display.Sprite;
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
	public class StarField extends Sprite {
		public function StarField():void { main = this; initialize(); }
	}
}

import flash.display.*;
//import flash.geom.*;
import flash.events.Event;

var SCREEN_WIDTH:int = 465, SCREEN_HEIGHT:int = 465;
var main:Sprite, g:Graphics;
//var stars:Vector.<Star> = new Vector.<Star>;
var stars:Array = new Array(1000);

function initialize():void {
	g = main.graphics;
	main.addEventListener(Event.ENTER_FRAME, update);
	for(var i:int = 0; i < 500; i++) stars[i] = new Star();
}

function update(e:Event):void {
	g.clear();
	for each(var s:Star in stars) s.update();
}

class Star extends Sprite {
	public var position:Object = new Object();
	public var velocity:Object = new Object();
	
	public function Star():void {
		position.x = Math.random() * SCREEN_WIDTH;
		position.y = Math.random() * SCREEN_HEIGHT;
		position.z = Math.random() * 8;
		
		velocity.x = position.z * -1/4;	// 5 being an arbitrary "speed up" number
		velocity.y = velocity.z = 0;
	}
	
	public function update():void {
		//position.incrementBy(velocity);
		position.x += velocity.x;
		if(position.x < 0) position.x = SCREEN_WIDTH;
		
		g.lineStyle(position.z, 0xffffff, 0.8);
		g.moveTo(position.x, position.y);
        g.lineTo(position.x + 1, position.y);
	}
}