7 Replies Latest reply on Aug 6, 2011 6:40 AM by LukeElChul

    adding to an arrary?????

    LukeElChul Level 1

      is there away to add the unit what gets attached to the array as unit4 and has an instance of unit4 and then if u press it again as unit5 with instance of unit5 and so on.......

       

      this is my array.

       

      var unitA:Array=[unit,unit1,unit2];

       

       

       

      ...............................................................

      var unit = 0;

      function addunit() {

           if (cash>=50) {

              var unit = attachMovie("unit", "unit"+units, _level0.getNextHighestDepth(), {_x:100, _y:100});

               unit += 1;

               cash -= 140;

           }

      }

      unit_btn.onRelease = addunit;

      .................................................................

        • 1. Re: adding to an arrary?????
          Ned Murphy Adobe Community Professional & MVP

          You could try using the push method of the Array class...

           

          var unitA:Array=[unit,unit1,unit2];

           

          ...............................................................

          var unit = 0;

          function addunit() {

               if (cash>=50) {

                  var unit = attachMovie("unit", "unit"+units, _level0.getNextHighestDepth(), {_x:100, _y:100});

                   unit += 1;

                   cash -= 140;

                   unitA.push(unit);

               }

          }

          unit_btn.onRelease = addunit;

          1 person found this helpful
          • 2. Re: adding to an arrary?????
            LukeElChul Level 1

            That didnt work i need it on the array so when it attaches it will work with another script

             

            could i do a trace are something to see if it goes on the array

            • 3. Re: adding to an arrary?????
              Ned Murphy Adobe Community Professional & MVP

              Try it without having two things named the same: unit vs unit

              1 person found this helpful
              • 4. Re: adding to an arrary?????
                LukeElChul Level 1

                i done as u said and i put a trace in.

                 

                and i get this

                 

                _level0.unit,_level0.unit1,_level0.unit2,NaN

                • 5. Re: adding to an arrary?????
                  LukeElChul Level 1

                  i changed it a bit and now i get this

                   

                  _level0.unit,_level0.unit1,_level0.unit2,_level0.unit

                   

                  but it still dosent work with this script.

                   

                   

                   

                  var unitA:Array=[unit,unit1,unit2];

                   

                  import mx.transitions.Tween;

                  import mx.transitions.easing.*;

                   

                  for(var i:Number = 0;i<unitA.length;i++){

                   

                  var unitB = unitA[i];

                  unitB.ivar=i;

                   

                  unitB.onRelease = function(){

                  this.onMouseUp = function(){

                  var t1:Tween = new Tween(this, "_x", None.easeNone, this._x, _xmouse, 10, true);

                  var t2:Tween = new Tween(this, "_y", None.easeNone, this._y, _ymouse, 10, true);

                  dy = _root._ymouse-this._y;

                  dx = _root._xmouse-this._x;

                  radianrotation = Math.atan2(dy, dx);

                  radianrotation = radianrotation*180/Math.PI;

                  this._rotation = radianrotation;

                  delete this.onMouseUp;

                  }

                  }

                  }

                  • 6. Re: adding to an arrary?????
                    Ned Murphy Adobe Community Professional & MVP

                    Your earlier code was wrong... too many things named "unit" (4 of them I believe, you should only have 1), so without seeing what you've changed it to, there's no telling what the problem might be.  But you could try using...

                     

                    unitA.push(this["unit"+units]);

                     

                    depending on what tat has changed to

                    • 7. Re: adding to an arrary?????
                      LukeElChul Level 1

                      i might just rewright my moving script

                       

                      Thanks!!!!!!!! anyway for all your help