4 Replies Latest reply on Sep 18, 2008 4:43 PM by system_critical55

    Problem with Push

      Hi, I'm trying to push MCs into an array. I've done it this way on other projects, but something odd is happening this time. I'm using a for loop to add mc names into an array, and when I trace the contents by index or the array .length past one I get undefined. It seems to hold the last index only. Is there something wrong with my syntax. Thanks.
        • 1. Re: Problem with Push
          kglad Adobe Community Professional & MVP
          where is boxes declared an array?
          • 2. Re: Problem with Push
            system_critical55 Level 1
            Hi, sorry boxes should read bubbleArray for starters. I was plugging in code from another file just to make sure there was no type o. It malfunctioned when named properly. The array isn't declared, but I tried declaring it. Still undefined. Should you have to declare the array in this case? Thanks.
            • 3. Re: Problem with Push
              Level 7
              You should always declare variables, it helps the compiler find errors for
              you and it can help you see the scope. Plus if bubbleArray is not an
              instance of the Array class, it wouln't have a push method.
              First, you are pushing _root['box' + i] when I think you want to push
              'bubble'. And I think you want _alpha not alpha. Also, to make things
              easier - attachMovie returns a reference to the clip you just attached -
              makes for less writing. The Help is nice...

              var bubbleArray = new Array();

              bubbulate = function (bNum)
              for (var i = 0; i < bNum; i++) {
              var ref = _root.attachMovie("bubble", "bubble" + i, i);
              ref._alpha = random(100) + 45;
              ref._xscale = random(50) + 10;
              ref._yscale = random(50) + 10;
              ref.bXMove = 0;
              ref.bYMove = 0;

              trace(bubbleArray[bubbleArray.length - 1]);

              Dave -
              Head Developer
              Adobe Community Expert

              • 4. Re: Problem with Push
                system_critical55 Level 1
                I figured out the problem. I was declaring the array in a function, which was called more than once. It erased the array every time, and left me with only one element. Thanks for the good tips anyway and for your time.