A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [QUESTION] Resetting setChildIndex

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    20

    Question [QUESTION] Resetting setChildIndex

    I used setChildIndex in my game to cause the enemies to fall behind another graphic, and it works beautifully. However, the game is set up so when the player wins or loses, they have the option to play another game. When the player selects this option though, the enemies move behind the entire background. Therefore, I assume that the index is not resetting when the new game starts. So my question is, is there a way to reset the index so that when the setChildIndex is encountered again the enemies are where they are supposed to be?

  2. #2
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    You should be removing all the enemies from the displayList when the game ends, and then adding them back on when the player restarts anyways. It should work then.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    20
    That's what I'm trying to figure out how to do, but the enemies are added within a function that activates on a timer, so I'm trying to figure out how to work with that. Here is the function so you can see what is going on.

    tm.start();

    function onstart (e:Event){

    em.Sprite = new enemy();
    em.x=Math.random()*550;
    addChild(em);
    //setChildIndex(em, 1);
    }

    That is how they are added, so now I am trying to figure out how to remove them so they are added again.

  4. #4
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    You should keep track of the enemies in an array, and then simply loop through that array and remove each of them when you're done with them.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    20
    I will give it a shot. Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center