Skip navigation
Currently Being Moderated

trying to understand and use an Array

Apr 6, 2012 5:43 PM

I would like to have a game where the player has three tries before the game stops or moves on to another level.

 

In this game an object jumps up with a mouseClick and if it doesn't hit it's target it falls where it crashes into a floor that uses hitTestObject.

 

This leads to a  restartBtn. but I want that movieClip to remain on the stage, which has an animation that splatters. A new MovieClip is put on to the stage and the cycle starts over.

Before this stage of the game s over I want the various movieClip splatters to be visible on the stage.

I thought an Array would help me achieve this result but I'm not familiar with using them dynamically.

I'm hoping someone can give me some tips as to what might work.

I have temporarily separated this problem from the rest of the code as I'm hoping it will be clearer.

This is where I left off and when I click the button it seems to eliminate the previous movieClip and introduce the next one.

 

But it seems like I'm missing someting so I thought I would post it as it is probably a problem that comes up a lot in games. Thanks

 

 

import flash.display.MovieClip;

import flash.events.MouseEvent;

 

 

var movieArray:Array = new Array();

 

 

movieArray = ["Egg_A","Egg_B","Egg_C"];

movieArray[0] = new Egg;

movieArray[1] = new Egg_B;

movieArray[2] = new Egg_C;

 

 

var myMovieClip:MovieClip;

 

 

init();

function init()

{

          for (var i:int = 0; i < movieArray.length; i++)

          {

                    emptyMC.addChild(movieArray[i]);

          }

 

 

}

 

 

mainBtn.addEventListener(MouseEvent.CLICK,changeEgg);

 

 

function changeEgg(evt:MouseEvent):void

{

          for (var i:int = 0; i < movieArray.length; i++)

          {

                    movieArray.splice(i,1);

          }

 

 

          init();

 

 

}

 
Replies
  • Currently Being Moderated
    Apr 6, 2012 6:57 PM   in reply to jandy48

    I don't see where an array is going to make anything remain.  Just having an instance created without removing it until you want it to go away is all you need.

     

    I don't see much reason with what you are doing with that array either.  First you assign a set of strings to it, then you replace those strings with instances of some Egg objects.  Then you add all the eggs to the display at once in your init() function (not one at a time), or you remove them all from the array with your change Egg function... calling the init() function after emptying the array isn't going to yield much since the init() function uses the array.

     
    |
    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