Skip navigation
HanseeFlashEntuiast
Currently Being Moderated

Need help to removeChild from loop! for(var i=0; i<10; i++)

May 28, 2012 5:09 AM

Tags: #problem #error #script #3.0 #action #3 #action_script_3 #event #movieclip #ac3 #game #actionscript3 #function #actionscript_3.0

Hello! Im working on a game project and having issue when looping to add more enemys.
What I want to do is like, if times run out and player get to failed frame, I want the child to get removed. but I find it hard to acces the var in the loop. I know it is some easy way..
but wil be prefect if someon have any help.

 

public function enemysLvl1(){

                              for(var i=0; i<10; i++){

                                        var frukt1:Frukt = new Frukt;

                                        addChild(frukt1);

                              }

 

Thank's!

 
Replies
  • Currently Being Moderated
    May 28, 2012 5:34 AM   in reply to HanseeFlashEntuiast

    Assign the instances to an array, then you can loop thru the array to remove them.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 5:42 AM   in reply to HanseeFlashEntuiast

    The best way would be doing what you said... try it out.  If you have a problem getting it working, then post the code that is not working.

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 8:00 AM   in reply to HanseeFlashEntuiast

    Either add each frukt1 instance to an array, as Ned said, or make an enemy container - a Sprite, and then just only add enemies to the container. You can then empty it by just calling removeChildAt(0) while container.numChildren > 0

    I tend to use Sprite containers a lot...

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points