5 Replies Latest reply on Jan 17, 2013 7:15 AM by kglad

    aim line - looping animation plz help!

    pa-pavel Level 1

      Hi.

       

      Hope someone can help me a bit stuck.

       

      import com.greensock.*;

      import com.greensock.easing.*;

       

       

      var TN = TweenNano;

      var newobjtimer;

      TN.to(p2,15,{_x:500});//

       

       

      newobjtimer = setInterval(createnewball, 600);

      function createnewball():Void

      {

                          this.attachMovie("Ball","ball1",{_x:p2._x, _y:p2._y});

                          trace(ball1._x)

      }

       

      The create ball keeps disapearing and I need to add a new ball each time the timer triggers and for all of them to be in their own place.

       

      Any help is appriciated.

       

       

      thx pavel

        • 1. Re: aim line - looping animation plz help!
          kglad Adobe Community Professional & MVP

          that's going to be a problem unless you stop adding movieclips at some point.

           

          but your error is you have failed to assign a depth for Ball.  the third parameter in attachMovie should be an available depth.

          1 person found this helpful
          • 2. Re: aim line - looping animation plz help!
            pa-pavel Level 1

            Hey,

             

            I got this now

             

            i++

            attachMovie("Ball","ball" + i,i,{_x:bullet._x, _y:bullet._y, _height:["ball" + i]._height-(i*.3), _width:["ball" + i]._width-(i*.3)});

             

            but the size of the 'ball' doesnt change how i want it...I want them to get small and smaller.

            And struggleing to rremove them all.

             

             

            cheers

            • 3. Re: aim line - looping animation plz help!
              kglad Adobe Community Professional & MVP

              :

               

               

               

              i++

              var ball:MovieClip = attachMovie("Ball","ball" + i,i,{_x:bullet._x, _y:bullet._y,});   // i'm not sure your positioning is what you want, either.

              ball._xscale=ball._yscale = 100-i*3;

               

              1 person found this helpful
              • 4. Re: aim line - looping animation plz help!
                pa-pavel Level 1

                Thx for the reply

                 

                here is the full code:

                 

                I am struggling to remove all the dots onMouseUp, always one dot gets left behind.

                 

                 

                 

                import com.greensock.*;

                import com.greensock.easing.*;

                var TN = TweenNano;

                var newobjtimer;

                var i = 0;

                var Speed

                var Gravity

                bullet._visible = true;

                gun.box._visible = false;

                gun.onMouseDown = function()

                {

                          tracker._visible = true;

                          gun.onEnterFrame = function()

                          {

                                    if (topbox.hitTest(_xmouse, _ymouse, true))

                                    {

                                              //trace("topbox");

                                              trgt._x = 450;

                                              trgt._y = 280;

                                              Speed = 15;

                                              Gravity = .5;

                 

                 

                                    }

                                    else if (bottombox.hitTest(_xmouse, _ymouse, true))

                                    {

                                              //trace("bottombox");

                                              trgt._x = 397;

                                              trgt._y = 350;

                                              Speed = 15;

                                              Gravity = 3.3;

                 

                                    }

                                    paramsF();

                                    initTrajectoryF();

                          };

                 

                 

                 

                 

                };

                 

                 

                gun.onMouseUp = function()

                {

                          trace(i)

                          for (var q = 0; q < i; q++)

                          {

                                     removeMovieClip(_root["ball" + q]);

                          }

                          i = 0;

                 

                          delete updateTrajectoryF ();

                          tracker._visible = false;

                          gun.box._visible = false;

                          delete gun.onEnterFrame;

                          lineobj.clear();

                          bulletSpeed = Speed;

                          bullet.gravity = Gravity;

                          xd = trgt._x - gun._x;

                          yd = trgt._y - gun._y;

                          dist = Math.sqrt(xd * xd + yd * yd);

                          flight = Math.ceil(dist / bulletSpeed);

                          bullet._x = gun._x;

                          bullet._y = gun._y;

                          bullet.xStep = xd / flight;

                          bullet.yStep = yd / flight;

                          bullet.yStep -= flight * bullet.gravity / 2;

                          bullet._visible = true;

                };

                 

                 

                bullet.onEnterFrame = function()

                {

                          with (this)

                          {

                                    _x += xStep;

                                    _y += yStep;

                                    yStep += gravity;

                                    if (_root.trgt.hitTest(_x, _y, true))

                                    {

                                              xStep = 0;

                                              yStep = 0;

                                              gravity = 0;

                 

                 

                                              //_visible = false;

                 

                 

                                    }

                          }

                };

                 

                 

                this.createEmptyMovieClip("lineobj",getNextHighestDepth());

                var trajectoryI:Number;

                 

                 

                //paramsF();

                //initTrajectoryF();

                 

                 

                function paramsF()

                {

                          bulletSpeed = Speed;

                          bullet.gravity = Gravity;

                          xd = trgt._x - gun._x;

                          yd = trgt._y - gun._y;

                          dist = Math.sqrt(xd * xd + yd * yd);

                          flight = Math.ceil(dist / bulletSpeed);

                          bullet._x = gun._x;

                          bullet._y = gun._y;

                          bullet.xStep = xd / flight;

                          bullet.yStep = yd / flight;

                          bullet.yStep -= flight * bullet.gravity / 2;

                          bullet._visible = true;

                }

                 

                 

                function initTrajectoryF():Void

                {

                          lineobj.clear();

                          lineobj.lineStyle(1,0xCD1B83,100);

                          lineobj.moveTo(gun._x,gun._y);

                          lineobj._visible = false;

                          updateTrajectoryF();

                }

                 

                 

                function updateTrajectoryF():Void

                {

                          lineobj.lineTo(bullet._x,bullet._y);

                          bullet._x += bullet.xStep;

                          bullet._y += bullet.yStep;

                          if (i < 15)

                          {

                                    i++;

                                    attachMovie("Ball","ball" + i,i,{_x:bullet._x, _y:bullet._y, _yscale :100-i*3, _xscale:100-i*3});

                          }

                          //trace("ball height " + ["ball" + i]._height);

                          bullet.yStep += bullet.gravity;

                          if (_root.trgt.hitTest(bullet))

                          {

                                    //i = 0;

                                    //trace(i)

                                    bullet.xStep = 0;

                                    bullet.yStep = 0;

                                    bullet.gravity = 0;

                                    bullet._visible = false;

                          }

                          else

                          {

                                    updateTrajectoryF();

                          }

                }

                • 5. Re: aim line - looping animation plz help!
                  kglad Adobe Community Professional & MVP

                  use:

                   

                    for (var q = 1; q <= i; q++)

                            {

                                       removeMovieClip(_root["ball" + q]);

                            }