3 Replies Latest reply on Feb 20, 2014 12:11 PM by Guy Lev

    Ball crossing around screen with if else

    Guy Lev

      Hi There

      I wish to make a ball go across the screen ( eventually it will be clouds )

      I wish that the ball will reach the end of the screen anf then do the animation again.

      This is the code I have written but the part that doesn't work is the part inside the else....

       

      Thanks

      Guy Lev

      Israel AUGM

       

      //setting the initial position of the ball

      var xpos = -100;

       

      // calling the symbol from library

      var myball = sym.createChildSymbol("ball", "Stage");

       

      //referencing the symbol

      var myballsym = myball.getSymbolElement();

       

      //setting the left posistion according tho the xpos var

      myballsym.css({"position":"relative","left":xpos});

       

      //checking the position of the ball

      if ( xpos <=200 ) {

      myballsym.animate({ "left": "400px" }, 2000);

      }else  {

      var xpos = -100;

      };

        • 1. Re: Ball crossing around screen with if else
          Guy Lev Level 1

          I did manage to do that the ball goes back to the initial position  - but the loop part doesn't really work like that....

          There must be another way of writning that...

           

          var xpos = -100;

          var myball = sym.createChildSymbol("ball", "Stage");

          var myballsym = myball.getSymbolElement();

          myballsym.css({"position":"relative","left":xpos});

          if ( xpos <=200 ) {

          myballsym.animate({ "left": "400px" }, 2000, function(){

          var xpos = 100;

          myballsym.css({"position":"relative","left":xpos});

          });

          };

          • 2. Re: Ball crossing around screen with if else
            SimonDBench Level 1

            Give this a try.

             

            var myball = sym.createChildSymbol("ball", "Stage");

            var myballsym = myball.getSymbolElement();

             

             

            animationComplete()

             

             

            function animationComplete(){

                      myballsym.css({"position":"relative","left":-100});

                      var animation = myballsym.animate({ "left": "400px" }, 2000, animationComplete);

            }

             

            The end function resets and triggers the animation so you end up with a loop when you call the animationComplete function.

             

            Simon

            • 3. Re: Ball crossing around screen with if else
              Guy Lev Level 1

              Great!

              Exactly what I need

              thanks again!!!