3 Replies Latest reply on May 2, 2012 10:01 PM by kglad

    Can you help me to find my mistake in code?

    vladimir a60943857

      Hello! Can you help me to find my mistake in code? Bottoms don't correctly work always and images shows inconsistently. Thank you.

       

      stop();

       

      import fl.transitions.Tween;

      import fl.transitions.easing.*;

       

      var arrayX:Array = [0,-600,-1200];

      var currentIndex:Number = 0;

      left_mc.addEventListener(MouseEvent.CLICK,navigate);

      right_mc.addEventListener(MouseEvent.CLICK,navigate);

      left_mc.buttonMode = true;

      right_mc.buttonMode = true;

       

      function navigate(e:MouseEvent):void

      {

                if (e.currentTarget == left_mc)

                {

                          currentIndex--;

                          checkArrows();

                          var stw1:Tween = new Tween(content_mc,"x",Back.easeOut,arrayX[currentIndex],arrayX[currentIndex - 1],4,true);

                }

                else

                {

                          currentIndex++;

                          var stw:Tween = new Tween(content_mc,"x",Back.easeOut,arrayX[currentIndex - 1],arrayX[currentIndex],4,true);

                          checkArrows();

                }

      }

      function checkArrows():void

      {

                if (currentIndex == 0)

                {

                          left_mc.visible = false;

                }

                else if (currentIndex == arrayX.length - 1)

                {

                          right_mc.visible = false;

                }

                else

                {

                          left_mc.visible = true;

                          right_mc.visible = true;

                }

      }

        • 1. Re: Can you help me to find my mistake in code?
          kglad Adobe Community Professional & MVP

          the first problem i see is the tweens are local to a function so they are eligible to be gc'd before they complete.  the second is you need to call checkArrows() when you start:

           

          stop();

           

          import fl.transitions.Tween;

          import fl.transitions.easing.*;

           

          var arrayX:Array = [0,-600,-1200];

          var currentIndex:Number = 0;

          left_mc.addEventListener(MouseEvent.CLICK,navigate);

          right_mc.addEventListener(MouseEvent.CLICK,navigate);

          left_mc.buttonMode = true;

          right_mc.buttonMode = true;

          checkArrows;

          var stw:Tween;

          function navigate(e:MouseEvent):void

          {

                    if (e.currentTarget == left_mc)

                    {

                              currentIndex--;

                              checkArrows();

                              stw = new Tween(content_mc,"x",Back.easeOut,arrayX[currentIndex],arrayX[current Index - 1],4,true);

                    }

                    else

                    {

                              currentIndex++;

                              stw= new Tween(content_mc,"x",Back.easeOut,arrayX[currentIndex - 1],arrayX[currentIndex],4,true);

                              checkArrows();

                    }

          }

          function checkArrows():void

          {

                    if (currentIndex == 0)

                    {

                              left_mc.visible = false;

                    }

                    else if (currentIndex == arrayX.length - 1)

                    {

                              right_mc.visible = false;

                    }

                    else

                    {

                              left_mc.visible = true;

                              right_mc.visible = true;

                    }

          }