Implementing a starfield - help please!

Hello folks,
I’m trying to implement a dynamic starfield into the game blaster mines (chapter 11) from the book “The Essential Guide To Flash Games” (from Jeff and Steve Fulton) but had no success yet.

U can download the framework and source codes from the book here: 8bitrocket.com/book

To be honest it’s driving me nuts. I built a separate starManager.as class and a BasicBlitArrayStar.as class for it. Also I’m using a pool for inactive and active stars (basically I think it’s the same method when building the projectiles or rather particles except that the stars move only when the mouse moves (using the same direction).

If u don’t know what I mean check out the parallax starfield from freeactionscript.com:

freeactionscript.com/2010/06/endless-starfield-parallax-scrolling

Currently it’s not working. The inactive pool is full of stars but when I try to draw them on the background I can see absolutely no star. Even when there is an active star available it doesn’t draw it on the background. The goal is a starfield that uses similar techniques from the framework like particles and projectiles do.

I have some things in mind like getting the child index for creating different star layers but currently I’m not able to realize it properly.

It would be so cool if someone could help me out with that problem. I spent a whole day figuring out why it doesn’t work and - to be honest - I have no clue. Any ideas?

Here are some code excerpts:

starManager.as:

package
{
import flash.display.BitmapData;
import com.framework_mod.src.BlitArrayAsset;
import com.framework_mod.src.BasicBlitArrayStar;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.geom.Point;
import flash.filters.GlowFilter;

//contains the design of the stars for Asteroid instance explosions; it will institute an object pool for
//memory optimization; Stars will be instances of the BasicBlitArrayStar class
public class StarManager
{
	public var starBitmapData:BitmapData;//this is the bitmapData look for the Stars
	
	public var stars:Array = []; //current active Stars array
	public var starPool:Array = [];//this attribute contains an array of the Stars in the pool
	//(inactive Stars)
	
	public var starAnimationFrames:Array = [];//Stars fade out as their life expires; the fade animation
	//frames will be stored in this array; it will be created with the BlitArrayAsset class
	
	public var starCount:int = 0;//this class-level variable will hold the length of the Stars array
	//(used for loops through active arrays)
	
	public var starPoolCount:int = 0;//this class-level variable will hold the length of the starPool array
	//(used for loops through inactive arrays)
	
	public var tempStar:BasicBlitArrayStar//temporary object used in loops
	public var starPoolMax:int = 500;//stores the total number of Star instances that can be on the
	//screen at a single time (total for the pool)
	
	/*public var starsPerExplode:int = starPoolMax / 20;//number of Star instances that will be created
	//for each explosion*/
	
	private var drawingCanvas:Shape = new Shape();//the canvas where the star look will be constructed
	private var point0:Point = new Point(0, 0);//a reusable Point instance for drawing operations
	
	//constructor ist leer
	public function StarManager() 
	{
		
	}
	
	//inaktiver starPool
			public function createStarPool(maxStars:int):void {
		//pool ist erstmal leer
		starPool = [];
		stars = [];
		//the function loops through a count of the passed in (maxStars) and pushes them
		//into the starPool array
		for (var starCtr:int = 0; starCtr < maxStars; starCtr++) {
			//bei jedem Durchgang der Schleife wird ein Partikel neu angelegt und in den Array geworfen
			var tempStar:BasicBlitArrayStar = new BasicBlitArrayStar(0, 1319,0, 999);
			starPool.push(tempStar);//wird in inaktiven Pool geschmissen
		}
	}
	
	
	public function createStar():void {
		var tempBlitArrayAsset:BlitArrayAsset = new BlitArrayAsset();
		starBitmapData = new BitmapData(1, 1, true, 0x00000000);
		
		drawingCanvas.graphics.clear();//Beginn der Vektor-Zeichnung der Stars
		drawingCanvas.graphics.lineStyle(1, 0xFFFFFF);
		drawingCanvas.graphics.drawRect(1, 1, 1, 1);
		
		starBitmapData.draw(drawingCanvas);//fertiger Vektor wird in starBitmapData reingeschmissen 
		
		/*spriteGlowFilter.color = levelColor;
		//Glow-Filter anwenden
		starBitmapData.applyFilter(starBitmapData, starBitmapData.rect, point0, spriteGlowFilter);*/
		
		tempBlitArrayAsset = new BlitArrayAsset();
		//the stars use the BlitArrayAsset class's createFadeOutArrayFrameBD t ocreate an array of faded
		//frames; when played in succession over a number of frame ticks, the stars will appear to fade and
		//burn out as they move away from the center of the explosion
		tempBlitArrayAsset.createFadeOutBlitArrayFromBD(starBitmapData, 30);//Reihe v. Bitmaps ausgeblendeter
		//Stars erzeugen
		
		starAnimationFrames = tempBlitArrayAsset.tileList;//fertige Frames werden in Array geschmissen
		trace("starManager.starAnimationFrames.length=" + starAnimationFrames.length );

	}
}

}

BasicBlitArrayStar.as:

package
{
import com.framework_mod.src.BasicBlitArrayObject;

//is a subclass of the BasicBlitArrayObject
public class BasicBlitArrayStar extends BasicBlitArrayObject
{
	
	/*public var lifeDelayCount:int = 0;//count of frames between changes in animation
	public var lifeDelay:int=0;//number of frames to count in lifeDelayCount (Verzoegerung der Animation)*/
	
	private var remove:Boolean = false;//will be set to true if the star needs to be removed from the screen
	
	//constructor for all of the children of BasicBlitArrayObject accepts in the same parameters as their parent
	//and pass them off with a call to super(): super (xMin, xMax, yMin, yMax)
	public function BasicBlitArrayStar(xMin:int,xMax:int, yMin:int, yMax:int  ) {
		super(xMin, xMax, yMin, yMax);
	}
	
	//this function's job is to apply the dx and dy (along with the speed) values to the object's nextX and nextY
	//attributes
	public function update(step:Number = 1):Boolean {
		remove = false;
		
		//the nextX and nextY values will be multiplied by the timeBasedModifier (step); this value is 
		//used to keep the distance that objects move in a single second constant no matter what frame rate the  
		//game SWF is playing at (bewegt das Objekt und sorgt fuer immer konstante Distanz-Zuruecklegung)
		nextX += dx * speed * step;//Richtung * Geschwindigkeit * Schritte
		nextY += dy * speed * step;
		
		//updating the lifeDelayCount variable
		/*if (lifeDelayCount > lifeDelay) {//Startschuss fuer Beginn der Animation (wenn true)
			lifeDelayCount = 0;
			frame++;
			//the animationList array length is used as the life span of the star; if the current frame of
			//the object is greater than the animationList length, the remove is set to true
			if (frame == animationList.length) {//Animation am Ende?
				remove = true;
			} else {
				//changing the bitmapData of the object
				bitmapData = animationList[frame];//naechstes Frame
			}
		} else {//Animation weiter verzoegern
			lifeDelayCount++;
		}*/
		
		//if the stars' nextX and nextY values are outside the boundaries set with the xMax, yMax and xMin,
		//yMin sets of variables, remove is also set to true
		if (nextX > xMax || nextX < xMin || nextY > yMax || nextY < yMin) {
			remove = true;
		}
		
		//the function returns the remove value back to the caller (wird benoetigt um im positiven Fall das 
		//Star aus Speicher zu entfernen (macht der caller)
		return(remove);

	}
	
}

}

Trying to fire it off inside the game:

//
private function createLevelbackground():void {
//*** background

		backgroundBitmapData.lock();
		
		starManager.starPoolCount = starManager.starPool.length - 1;//zaehlt die inaktiven Stars im Pool
		//draw 800 random stars (single pixels) to the backgroundBitmapData
		stars: for (var starCtr:int = starManager.starCount; starCtr >= 0; starCtr--) {
			//setPixels32:Sets the color and alpha transparency values of a single pixel of a BitmapData object.
			//This method is similar to the setPixel() method; the main difference is that the setPixel32()
			//method takes an ARGB color value that contains alpha channel information.
			//backgroundBitmapData.setPixel32(int(Math.random() * 1319), int(Math.random() * 999), 0x0066ff);
			tempStar = starManager.starPool[starCtr];//tempStar wird entspr. Teil aus Array zugewiesen
			tempStar.point.x = tempStar.x;//??
			tempStar.point.y = tempStar.y;
			
			tempStar.x = int(Math.random() * 1319);
			tempStar.y = int(Math.random() * 999);
			
			//tempStar.x = 660;
			//tempStar.y = 500;
			
			starManager.stars.push(tempStar);//in aktiven Pool schmeissen
			starManager.starPool.pop();//Star aus inaktivem Pool abziehen
			
			//var starBitmap:Bitmap = new Bitmap(starManager.starBitmapData);
			backgroundBitmapData.draw(starManager.starBitmapData);
		}
		
		backgroundBitmapData.unlock();
	}

Rendering the stuff:

private function renderBg():void {

	backgroundStarsBitmapData.copyPixels(backgroundBitmapData, backgroundBitmapData.rect, point0);
	
		for each (tempStar in starManager.stars) {
			
			tempStar.render(backgroundBitmapData);
			
		}

}

Updating it:

private function update(timeDifference:Number = 0):void {

for each (tempStar in starManager.stars) {
tempStar.update(step);
}

}