Var x:
We set x to _root.getNextHighestDepth(); which is self-explanatory,
But in the next line we add it to the new name of "bullet", like this;
_root.attachMovie("bullet", "bullet"+x, x)
And we added it as the depth of the bullet. Pretty good huh?
So each bullet created has its own unique name and its own depth, solving any depth and name related problems.

In the next 2 lines we set where the bullet will be attached on the stage.
There are lots of ways to do this, here are some examples:
bullet._x=250
bullet._y=250
or to make it dynamic (so the position doesn't always have to be 250)
xPos=250
yPos=250
bullet._x=xPos
bullet._y=yPos
and then just make a code to change xPos and yPos
or the most used and probably the most dynamic way is just attach it a MovieClip's _x and _y ('turret') that is already on the stage.
bullet._x=turret._x
bullet._y=turret._y
and so if you were to have the turret as a moving character or A.I. enemy it would always attach the bullet to where the MC is.

randomNum and _rotation
An easy way to think of how randomNum is calculated is lets say the bulletOffset=10. random(bulletOffset) would return a number between 0 and 10, lets say it was 3. So random(bulletOffset)-bulletOffset/2, again lets say random(bullOffset) by itself returned 3, so 3 - 5 = -2. The max number it now can return is 5 and the minimum is -5. This is a great way for fluxuating between a positive and negative number.
So now we set bullet._rotation to equal the turret's rotation plus our +- number, creating an equal amount of offset on both the upper side of the turret and lower.

If we did not subtract the half of bulletOffset from the random the bullets would appear to always be fluxing on the lower side of the turret and never go past that point.

These next 2 lines are just trigonometry, you don't have to even understand most of this to be able to use it fluently.
What you need to know though is this,
Take this example:
bullet.xSpeed= Math.cos(Math.PI/180 * bullet._rotation)*bulletSpeed

-Math.cos is generally used for the _x values, unless (in this file) you want the bullets to be fired the wrong way
-Always use the bullet._rotation and not the turret, because you have calculated the bullets rotation already with randomNum, otherwise there would be no offset.
-Math.PI/180 * bullet._rotation can be said in almost any order:
(Math.PI * bullet._rotation/180)
(bullet._rotation/180 * Math.PI)
(bullet._rotation * Math.PI/180)
-Unless you want your bullets to be extremely slow, multiply them by bulletSpeed
-Math.sin is generally used for _y values. Unless you like confusion and frustration?

onEnterFrame
Now that we have every thing set we can let the magic happen, or just make the bullets...GO.
We say bullet.onEnterFrame=function(){, so the computer knows that its controlling the same bullet that it created with its identifier x.
Then we execute
this._x+=this.xSpeed
this._y+=this.ySpeed
this.life++
So for _y and _x there values are added to be the bullet's unique xSpeed and ySpeed (thats why we use 'this.xSpeed' and not just xSpeed, otherwise the bullets would all use the same value, which currently is set as 0 so theres not much fun there).
this.life is increased 1 every frame, so,
if(this.life>totalLife){
this.removeMovieClip();
this.unloadMovie();
}
So the totalLife variable is global and used by every bullet, and since this.life is increased one every frame, totalLife can just be seen as the total amount of frames the bullet is in existence.
this.removeMovieClip(); removes the bullet from the stage (I THINK).
this.unloadMovie(); removes the bullet from memory (I THINK).
I use both just to ensure that CPU usage is minimal, or plain out just no lag.
I'm not sure if its necessary or you can use just one, If you know correct me PLEASE.

Now we end the if statement and bullet.onEnterFrame and execute reload();, I explained this already up above.

Now to create the code to actually use the function
Next Page!