0
votes

So I made an array of fireballs and added them to the screen like this:

        for (var i :Number = 0; i < fireballs; i++)
        {
            var mcFireball :fireball = array[i];
            moveEnemy(mcFireball);
            //array[i].moveEnemy();
        }

I can't figure out how to remove them from the frame when I want to restart and how to make it so that if I run into them I lose. I have tried removeChild() but I might be doing it wrong, I'm not sure. Do I need to make a new function that will use the array and then remove them that way? Also how do I make them hit detectable?`

2

2 Answers

1
votes

My usual approach is to store those objects in an array (or vector) and the just loop through the array and remove the unneeded ones.

Also, if you addChild() to some other object, like this:

myObject.addChild(myMC);

You need to call the removeChild() from that object, like this:

myObject.removeChild(myMC);

If you don't know the parent, you can of course use some construction like:

if (myMC.parent)
myMC.parent.removeChild(myMC);

but it's considered poor style and you shouldn't use hacks if you want your code to be maintainable ;)

1
votes

Theres an awesome tutorial series on YouTube by user: PointClickWin

https://www.youtube.com/playlist?list=PL5A9B8F405B31823A The series (in the provided link) covers this very thing you're trying to do! As others before have said: "Why re-invent the wheel?". Those tutorials are VERY handy for basing and re-purposing your code on, I found them very easy to follow and fairly in-depth! Good Luck and happy coding!