CODE
var d:Number = 0;
var rX, rY, i:Number;
//---------------------------
var xBounds:Number = 550;
var yBounds:Number = 400;
//---------------------------
function createBad(n:Number):Void {
var c:Number = 0;
while (c<n) {
d++;
_root.attachMovie("badGuy", "b"+d, d);
i = Math.round(Math.random());
if (i == 0) {
rX = Math.random()*(xBounds+100)-50;
rY = Math.round(Math.random())*(yBounds+100)-50
;
} else {
rX = Math.round(Math.random())*(xBounds+100)-50
;
rY = Math.random()*(yBounds+100)-50;
}
_root["b"+d]._x = rX;
_root["b"+d]._y = rY;
c++;
}
}
EXPLANATION
First paste all that code in your first frame, then right click on your bad guy in the library, then click "Linkage...", then Click "Export for Actionscript" and "Exports in first Frame" (if not clicked already), then in the indentifier box type "badGuy". To create bad guys type this somewhere in your code:
_root.createBad(1); //that will create 1 bad guy somewhere outside the bounds
or
_root.createBad(10); //that will create 10 bad guys all at the same time outside of the bounds
You can also change the xBounds and yBounds to match your game.