2 Replies Latest reply: Apr 7, 2012 3:49 AM by jandy48 RSS

    trying to understand and use an Array


      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;




      function init()


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












      function changeEgg(evt:MouseEvent):void


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










        • 1. Re: trying to understand and use an Array
          Ned Murphy MVP

          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.

          • 2. Re: trying to understand and use an Array
            jandy48 Community Member



            So I might try placing three or more instances on the stage and changing thier visibility as I need to use them.


            I'll keep playing with it but at least I'm getting more famiiar with Arrays.