Adding movie clip to stage
Hi, I am trying to add x amount of movieclips to the stage with their own unique _x value. Also with each movie clip added i need to add an array with a smiler name. I tried this code.
Actionscript Code:
enemycount = 46;
for (i=1; i<enemycount+1; i++) {
this["currentenemy"+(i)]=_level0.enemydatabase[0];
this.attachMovie("BrownFox", ["enemy"+i], 101, {_x:100, _y:219});
}
for (i=enemycount; i<51; i++) {
this["currentenemy"+(i)]=_level0.enemydatabase[1];
}
trace (this.enemy1._x);
trace (this.currentenemy45);
under the attachmovie I have ["enemy"+1] but when i trace enemy1 it returns undefined. But when I put ["enemy"+1] it returns the _x value. also if I put _x: i * 5, I only see one movie clip so I have a feeling they all have the same _x and_y value. basically I wanna be able to add 2 enemys to the stage with out over lapping, and the option to add 50 with out too much over lapping (would like to avoid overlapping by also giving various y depths, between 200 and 250)
alright this one works well
Thanks now it will add them but obviously in a really stupid order.
I tried to fix things up a bit but there is still a lot of chaos.
I am wondering (this is for my battle system) if my best option would be to find 50 locations (x and y) on the stage that are a bit scattered (my enemies can be far or close, so I would need 50 far enemy locations and 5 close enemy locations so i can have a mix of far and close or all far or all close). I figure I could add all locations to an array so then I can pull up the array slots for each spot. But would this cause loop falures when assigning them, and would it be too much code?
also, I tried using this code but it created a loop crash.
Actionscript Code:
enemycount = 45;
for (i=1; i<enemycount+1; i++) {
trace(i);
e = random(100);
a = random(2);
if (a<=1) {
s = random(80);
} else {
s = random(-80);
}
if (100+(i*40+e/0.8-s)<=440) {
this["currentenemy"+(i)] = _level0.enemydatabase[0];
this.attachMovie("BrownFox", ["enemy"+i], 200+(i*5+e-s), {_x:100+(i*40+e/0.8-s), _y:200+(i*5+e-s)});
} else {
i--;
}
}
for (i=enemycount; i<51; i++) {
this["currentenemy"+(i)] = _level0.enemydatabase[1];
}
that was a fail attempt
when i tried
Actionscript Code:
enemycount = 45;
for (i=1; i<enemycount+1; i++) {
trace(i);
e = random(100);
s = random(200);
f = random(80)
this["currentenemy"+(i)] = _level0.enemydatabase[0];
this.attachMovie("BrownFox", ["enemy"+i], 200+(i*5+e-s), {_x:100+(i*40+e/0.8-s), _y:200+(i*5+e-f)});
}
for (i=enemycount; i<51; i++) {
this["currentenemy"+(i)] = _level0.enemydatabase[1];
}
they were spread out but there was a lot that were off the screen and they are close together a lot.
http://img52.imageshack.us/img52/6653/wtfrs.jpg
I know 50 is hard to fit thats why I have to have the depth working so the ones with a higher y value are in front, also the farther they are in the back the smaller their height and width will be. any suggestions? or something that could point me in a positive direction?
Thanks guys.