Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:18:49+00:00 2026-06-12T21:18:49+00:00

I’m wondering if it is possible to reset / reload / reconstruct an array

  • 0

I’m wondering if it is possible to reset / reload / reconstruct an array order?

I’m making this “Space Invaders” game and the enemy’s need to restart to it’s position when the game is being restarted. When I shoot down the enemy’s and reset my game, the enemy’s I’ve killed keep being gone.

So here’s some of the code responsible:

var spiderArray:Array = new Array(enemyField.enemy1,enemyField.enemy2,
                             enemyField.enemy3,enemyField.enemy4,
                             enemyField.enemy5,enemyField.enemy6,
                             enemyField.enemy7,enemyField.enemy8,
                             enemyField.enemy9,enemyField.enemy10,
                             enemyField.enemy11,enemyField.enemy12,
                             enemyField.enemy13,enemyField.enemy14,
                             enemyField.enemy15,enemyField.enemy16,
                             enemyField.enemy17,enemyField.enemy18,
                             enemyField.enemy19,enemyField.enemy20,
                             enemyField.enemy21,enemyField.enemy22,
                             enemyField.enemy23,enemyField.enemy24,
                             enemyField.enemy25,enemyField.enemy26,
                             enemyField.enemy27,enemyField.enemy28,
                             enemyField.enemy29,enemyField.enemy30,
                             enemyField.enemy31,enemyField.enemy32,
                             enemyField.enemy33,enemyField.enemy34,
                             enemyField.enemy35,enemyField.enemy36,
                             enemyField.enemy37,enemyField.enemy38,
                             enemyField.enemy39,enemyField.enemy40,
                             enemyField.enemy41,enemyField.enemy42,
                             enemyField.enemy43,enemyField.enemy44,
                             enemyField.enemy45,enemyField.enemy46,
                             enemyField.enemy47,enemyField.enemy48,
                             enemyField.enemy49,enemyField.enemy50,
                             enemyField.enemy51,enemyField.enemy52,
                             enemyField.enemy53,enemyField.enemy54,
                             enemyField.enemy55,enemyField.enemy56,
                             enemyField.enemy57,enemyField.enemy58,
                             enemyField.enemy59,enemyField.enemy60,
                             enemyField.enemy61,enemyField.enemy62,
                             enemyField.enemy63,enemyField.enemy64,
                             enemyField.enemy65,enemyField.enemy66);

Now the place where the enemy’s are being killed:

function enemyHitTest():void {
//for each of the three spiders
for(var i:int = 0; i < spiderArray.length; i++) {
    //the each of the six bullets
    for(var j:int = 0; j < 6; j++) {
        //don't consider bullets that aren't in play:
        if(bulletArray[j].y > SpelerMC.y) continue;
        if(spiderArray[i].hitTestObject(bulletArray[j])) {
            score += 10;
            scoreTxt.text = score.toString();
            trace("Invader " + i + " neergeschoten!");
            spiderArray[i].parent.removeChild(spiderArray[i]);
            bulletArray[j].x = j * 70 + 100;
            bulletArray[j].y = 595;
        }
    }
}

Now I think I need to put some sort of theArray.pop(); or something, but don’t know how to use it, but I need to place it in this function:

function startGame() {
trace("Start het spel opnieuw...");
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
gameTimer.start();
enemyField.x = 400;
enemyField.y = 160;
SpelerMC.x = 83;
SpelerMC.y = 531;
}

Please help me! Have been searching for 5 hours already.
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:18:51+00:00Added an answer on June 12, 2026 at 9:18 pm

    to remove element number i use array.splice(i, 1); ( http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice().com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice%28%29) but keep in mind that array.length will decrease
    to reset the array just invoke spidersArray = new Array(enemyField.enemy1, etc) again

    UPDATE
    in in the enemyHitTest function i changed the removing condition to if(enemyArray[i].visible && enemyArray[i].hitTestObject(laserArray[j])) and enemyArray[i].parent.removeChild(enemyArray[i]); to enemyArray[i].visible = false;
    and added

    function respawnEnemies():void{
        for(var i:int = 0; i < enemyArray.length; i++) {
            enemyArray[i].visible = true;
        }
    }
    

    to call it from startGame

    full code here

    upd 2
    so the problem was not in resetting the array but in the fact that your enemyField and its’ enemies were added to stage manually and removed programmatically so there was no code to call to bring them back

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.