# Starfield class

**URL:** <https://forum.kirupa.com/t/starfield-class/157924>\
**Category:** open source\
**Created:** [August 5, 2005, 5:04am UTC](https://forum.kirupa.com/t/starfield-class/157924 "2005-08-05T05:04:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)\
**Post date:** [August 5, 2005, 5:04am UTC](https://forum.kirupa.com/t/starfield-class/157924/1 "2005-08-05T05:04:26Z")

</div>

Hey guys, I was recently working on a new game [www.createage.com/Game/main.html](http://www.createage.com/Game/main.html) and I needed to get a cool starfield effect, this really isn’t a big deal but I figured that you guys could mess around with it, I don’t know do whatever you want with it really, the class Definition is as follows:

```php
// put in flash===== var starfield = new Starfield(_root, 300, 5, -1);
class Starfield
{
	private var target : MovieClip;
	public function Starfield (target : MovieClip, starCount : Number, maxSpeed : Number, dir : Number)
	{
		this.target = target;
		createStars (starCount, maxSpeed, dir);
	}
	private function createStars (starCount : Number, maxSpeed : Number, dir : Number) : Void
	{
		for (var i = 0; i < starCount; i ++)
		{
			var mc;
			var dist : Number = Math.round (Math.random () * 100);
			mc = target.createEmptyMovieClip ('star' + i, i);
			mc.lineStyle (1, 0xFFFFFF, dist);
			mc.lineTo (0, 1);
			mc._x = Math.random () * 550;
			mc._y = Math.random () * 400;
			mc.speed = (dist / 100) * maxSpeed;
			mc.onEnterFrame = function ()
			{
				
				if (dir >= 0)
				{
					this._x += this.speed;
					if (this._x > 550)
					{
						this._x = 0;
					}
				} else 
				{
					this._x -= this.speed;
					if (this._x < 0)
					{
						this._x = 550;
					}
				}
			}
		}
	}
}

```

You guys should know how to use it ;), anyway enjoy.  
… oh yeah if you use this, the dots are WHITE so set your background to a dark color.

-Michael
