Call an Array From a hitTest?

can this be done? if so, how?
i’m trying to make two duplicated movie clips check for any of the others
ie bullet239 hitting badguy92
thanks

myarray = [_root.baddy1, _root.baddy2, _root.baddy3, _root.baddy4, _root.baddy5]
for (i=0; i<myarray.length; i++) if (bullet.hitTest(myarray*)) { break; trace(myarray*+" is hit!") }

is there a way to not type _root.baddy, just have the numbers, like baddy1-9999999

for (i=1; i<=99999999999999999999999999; i++) {
if(_root["baddy"+i].hitTest(bulletMC)) {
trace("hit!");
break;
}
}

OR

for (i=1; i<=99999999999999999999999999; i++) {
if(eval("baddy"+i).hitTest(bulletMC)) {
trace("hit!");
break;
}
}

the second example uses eval, it’s decprecated (The flash 5 way), and the first uses the flash mx way. The second example, though, is faster…

whoa, whoa, whoa…i hope you’re not serious, ahmed. this thing’s gonna run forever.

Do i remember you asking this type of question before, yeildarb?

As much as possible, try to stay away from long for loops. Nobody’s gonna want to watch a flash movie that freezes their computer.

this would run slow? is there a way to do it w/o it running slow?

set ranges for your mcs… like set your bullets to go 1-100 and your badguys to go 101-200 and if bullets get to 100 reset the counter to 1 and if your badguy counter gets to 200 reset it to 101 and then in your for loop you can do

for(i=1;i<=100;i++)
{
for(j=101;j<=200;j++)
{
//if i hits j then do stuff
}
}

and to go even faster then make even smaller ranges like 1-50 and 51-100 or whatever you want… fastest i could see is setting the ranges so its just enough for stuff to always be on the screen… because when you reset your variables say when it gets to 100 you set it back to 1… if 1 is still on the screen its going to get written over and the old #1 will disappear

anyway hope it helps

Shame on you Ahmed !!:bad: :bad: :bad:

Ofcourse there is only one method of doing this correctly:
[AS]MovieClip.prototype.explode = function()
{
trace(“POW! (” + this + " exploded)");
}

for (var i in _root)
{
obj = _root*;
if (typeof(obj) == “movieclip” && obj._name.substr(0,5) == “baddy”)
{
hit = obj.hitTest(bulletMC);
//if (hit)
obj.explode();
}
}[/AS]

If loops through all the object in the _root.
Then it checks if its a MovieClip, and if the name starts with “baddy”.

If a match has been found it checks if there is a collision with the bullet, and if so, it “explodes” the movieclip.
(MovieClip.prototype.explode() currently only traces a confirm)

nice… i didnt even think of that… thats a lot faster than my method… instead of checking every one against every other one… the game would run a lot faster…

but there is more than 1 bullet…

that AS is in the bullet right? with bulletMC = this?

yeah you put it in the main bullet that you will be duplicating and then each duped one will check itself against the enemies

Very good … check my explaination here:

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=31973