7 Replies Latest reply on Aug 5, 2011 2:11 PM by Ned Murphy

    hmm is this posible????

    LukeElChul Level 1

      so ive got 2 units (unit, unit1) and ive got seperate moving scripts for both of them but soon i plan to create multiple units in the scene like 10 are 20 so is there a way to use a script like this but linked to an array are something so u can move 10 are 20 units seperately just with this short script.

       

       

      import mx.transitions.Tween;

      import mx.transitions.easing.*;

      unit.onRelease = function(){

      unit.onMouseUp = function(){

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

      var t2:Tween = new Tween(unit, "_y", None.easeNone, unit._y, _ymouse, 5, 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 unit.onMouseUp;

      }

      }

       

      help please

        • 1. Re: hmm is this posible????
          kglad Adobe Community Professional & MVP

          sure, if they're all tweening to the same point or to some function of their array index number:

           

          var unitA:Array=[unit0,unit1,...];

           

           

          import mx.transitions.Tween;

          import mx.transitions.easing.*;

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

          var unit = unitA[i]l

          unit.ivar=i;  // if units are movieclips you'll probably want this

          unit.onMouseUp=function(){

          this.onRelease = function(){

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

          var t2:Tween = new Tween(this, "_y", None.easeNone, unit._y, _ymouse, 5, 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;

          }

          }

          }

           

          1 person found this helpful
          • 2. Re: hmm is this posible????
            LukeElChul Level 1

            sorry for the delay in posting my replay.

             

            i get an error saying

             

             

            **Error** Scene=Scene 1, layer=Towers, frame=1:Line 1: Unexpected '.' encountered     var unitA:Array=[unit0,unit1,...]; Total ActionScript Errors: 1 Reported Errors: 1

            • 3. Re: hmm is this posible????
              Ned Murphy Adobe Community Professional & MVP

              That error appears to be saying you have something wrong with the array in line 1... an unexpected dot ( . )

              1 person found this helpful
              • 4. Re: hmm is this posible????
                LukeElChul Level 1

                i fixed it but is there any way to make them move seperately.

                 

                for example: unit1 moves to the left corner while unit stays still

                • 5. Re: hmm is this posible????
                  Ned Murphy Adobe Community Professional & MVP

                  I'm not clear on the intention as far as where you expect things to be moving, but you might want to try changing the two lines of code from...

                   

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

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

                   

                  to

                   

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

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

                   

                  and see i f that does what you had before.

                  • 6. Re: hmm is this posible????
                    LukeElChul Level 1

                    Thanks u poited me in the right direction and i changed a few things and got it working.

                     

                    THANKS!!!!!!!!!!!!!!!

                    • 7. Re: hmm is this posible????
                      Ned Murphy Adobe Community Professional & MVP

                      You're welcome