Now for the fun part. In the main timeline, add this piece of code to frame 1 (there should only be one frame) to create multiple instances of your particle. Remember that all the previous code is attached to your particle and so will be duplicated with it, making each particle self-sufficient:


for (n=1; n<100; n++) {
	particlename.duplicateMovieClip("particlename"+n, n);
}

// where particlename is the instance name of your particle. Mine is called  Jeff.

You'll also need to change the initial xval,yval,and zval properties to random values, otherwise they'll all be in the same spot:

	xval = random(500);
	yval = random(500);
	zval = random(500);

Now you should have 100 shiny new particles moving about as if they were in a 3D space! If you are using an older version of flash, the code assigned to your particle may not duplicate with the clip.. if this is the case, open your clip and attach your code to a movie clip inside that one.. and it will then definitely be duplicated. (remember to delete the code on the outer clip if you do this)

You may notice that your center point is in the far left corner at the moment. To change this to centre screen you need to add an offset value to your equations like this:

in the (load) section:


	offsetx = 275; // this is the midpoint of your flash screen
	offsety = 200; // so is this

in the (enterframe) section:


	this._x = offsetx + scaler*xval;
	this._y = offsety + scaler*yval;

You'll then need to adjust the random initial values to cater for the blank sides of the screen:


	xval = random(500)-random(500);
	yval = random(500)-random(500);

so now the whole body of code attached to your particle looks like this:


onClipEvent (load) {
	xval = random(500)-random(500);
	yval = random(500)-random(500);
	zval = random(500);
	offsetx = 275;
	offsety = 200;
	speed=5;
	f = 300;
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.LEFT)) {
		xval += speed;
	} else if (Key.isDown(Key.RIGHT)) {
		xval -= speed;
	}
	if (Key.isDown(Key.UP)) {
		yval += speed;
	} else if (Key.isDown(Key.DOWN)) {
		yval -= speed;
	}
	if (Key.isDown(Key.SPACE)) {
		zval += speed;
	} else if (Key.isDown(Key.CONTROL)) {
		zval -= speed;
	}
	scaler = f/(f+zval);
	this._x = offsetx+scaler*xval;
	this._y = offsety+scaler*yval;
	this._xscale = 100*scaler;
	this._yscale = 100*scaler;
}

If you notice some quirky behaviour then that's because some particles are travelling to a depth which is less than 0. To stop that just add this code where you're subtracting from zval:


	if (zval>0) {zval-=5;}

Here's a quick 'game'/toy called SunKiller I made using this code:

Check back soon for the second article to follow, Rotation in 3D.