7 Replies Latest reply on Jun 25, 2011 2:34 PM by kglad

    Why banner animation suddenly stop

    tomazsr

      Hi,

       

      First, this is my first as3 banner

      I write banner animation in as3 (Flash CS5) So I dont use any timeline frames. All code is on 1st frame on actions layer.

      When I publish banner and start it in browser it runs nice for a while but than suddenly stop. I test in 3 major browser

      and it is the same.

      I didnt find anything on net so I m a little desperate or maybe its totaly wrong to write loop animations in as3.

       

      Thank you for any idea

      Tomaz

        • 1. Re: Why banner animation suddenly stop
          kglad Adobe Community Professional & MVP

          if you use the flash tween class, making a tween local to a function is the most common cause of a tween stopping suddenly.

          • 2. Re: Why banner animation suddenly stop
            tomazsr Level 1

            Yes I use lots of Tweens like this:

             

            // 1 screen
            function PlayTitle():void
            {
            addChild(WallTitleOut);
            var TweenAlphaWall = new Tween(WallTitleOut,"alpha",Strong.easeOut,0,1,3,true);

            TitleOut.x = SceneMiddleX;
            TitleOut.y = SceneMiddleY;
            addChild(TitleOut);

            //scale
            var TweenAlpha = new Tween(TitleOut,"alpha",Strong.easeOut,0,1,3,true);
            var TweenScaleX = new Tween(TitleOut,"scaleX",Strong.easeOut,0,1,3,true);
            var TweenScaleY = new Tween(TitleOut,"scaleY",Strong.easeOut,0,1,3,true);
            TweenScaleY.addEventListener(TweenEvent.MOTION_FINISH, onFinishPlayTitle);

            }

            function onFinishPlayTitle(evt:TweenEvent):void
            {
            removeChild(WallTitleOut);
            PlayCounter();
            }

            // 2 screen
            function PlayCounter():void
            {
            SubTitleOut.x = SceneMiddleX;
            SubTitleOut.y = SceneMiddleY-40;
            addChild(SubTitleOut);

            var TweenAlphaSubTitle = new Tween(SubTitleOut,"alpha",Strong.easeOut,0,1,2,true);
            var TweenScaleXSubTitle = new Tween(SubTitleOut,"scaleX",Strong.easeOut,0,1,2,true);
            var TweenScaleYSubTitle = new Tween(SubTitleOut,"scaleY",Strong.easeOut,0,1,2,true);

            CounterOut.x = SceneMiddleX;
            CounterOut.y = SceneMiddleY+40;
            addChild(CounterOut);

            //scale
            var TweenAlpha = new Tween(CounterOut,"alpha",Strong.easeOut,0,1,3,true);
            var TweenScaleX = new Tween(CounterOut,"scaleX",Strong.easeOut,0,1,3,true);
            var TweenScaleY = new Tween(CounterOut,"scaleY",Strong.easeOut,0,1,3,true);
            TweenScaleY.addEventListener(TweenEvent.MOTION_FINISH, onFinishPlayCounter);
            }
            function onFinishPlayCounter(evt:TweenEvent):void
            {
            removeChild(SubTitleOut);
            removeChild(CounterOut);
            PlaySecretaryThinking();
            }

            and so on until  in the end I call main function again:

             

            function onFinishPlayFly(evt:TweenEvent):void
            {
            removeChild(FlyTextOut);
            removeChild(TheifOut);
            removeChild(HorseOut);
            removeChild(FlyOut);
            RepeatAnimation()
            }


            // DO LOOP
            function RepeatAnimation():void
            {

            MainAnimation();
            }

            What I doing wrong?

             

            Tomaz

            • 3. Re: Why banner animation suddenly stop
              kglad Adobe Community Professional & MVP

              the 6 tweens in bold below are local to PlayCounter() and will be gc'd by flash (and the tweens will suddenly stop) whenever flash decides to clear (what it thinks) is unneeded memeory:

               

               

              function PlayCounter():void
              {
              SubTitleOut.x = SceneMiddleX;
              SubTitleOut.y = SceneMiddleY-40;
              addChild(SubTitleOut);

              var TweenAlphaSubTitle = new Tween(SubTitleOut,"alpha",Strong.easeOut,0,1,2,true);
              var TweenScaleXSubTitle = new Tween(SubTitleOut,"scaleX",Strong.easeOut,0,1,2,true);
              var TweenScaleYSubTitle = new Tween(SubTitleOut,"scaleY",Strong.easeOut,0,1,2,true);

              CounterOut.x = SceneMiddleX;
              CounterOut.y = SceneMiddleY+40;
              addChild(CounterOut);

              //scale

               

              var TweenAlpha = new Tween(CounterOut,"alpha",Strong.easeOut,0,1,3,true);


              var TweenScaleX = new Tween(CounterOut,"scaleX",Strong.easeOut,0,1,3,true);


              var TweenScaleY = new Tween(CounterOut,"scaleY",Strong.easeOut,0,1,3,true);

              TweenScaleY.addEventListener(TweenEvent.MOTION_FINISH, onFinishPlayCounter);

               

              }

               

              //////////////////////////////////

              to remedy, don't make your tween variables local to a function:

               

              var TweenAlphaSubTitle:Tween;

              var TweenScaleXSubTitle:Tween;

              etc

               

              function PlayCounter():void
              {
              SubTitleOut.x = SceneMiddleX;
              SubTitleOut.y = SceneMiddleY-40;
              addChild(SubTitleOut);

              TweenAlphaSubTitle = new Tween(SubTitleOut,"alpha",Strong.easeOut,0,1,2,true);
              TweenScaleXSubTitle = new Tween(SubTitleOut,"scaleX",Strong.easeOut,0,1,2,true);
              TweenScaleYSubTitle = new Tween(SubTitleOut,"scaleY",Strong.easeOut,0,1,2,true);

              CounterOut.x = SceneMiddleX;
              CounterOut.y = SceneMiddleY+40;
              addChild(CounterOut);

              //scale

               

              TweenAlpha = new Tween(CounterOut,"alpha",Strong.easeOut,0,1,3,true);

              TweenScaleX = new Tween(CounterOut,"scaleX",Strong.easeOut,0,1,3,true);

              TweenScaleY = new Tween(CounterOut,"scaleY",Strong.easeOut,0,1,3,true);

               

              TweenScaleY.addEventListener(TweenEvent.MOTION_FINISH, onFinishPlayCounter);

               

              }

              • 4. Re: Why banner animation suddenly stop
                tomazsr Level 1

                Thx.

                I put all Tweens vars out of functions and run banner ....  and still runing

                 

                Is this only with Tweens or I must take care with other classes to?

                 

                T

                • 5. Re: Why banner animation suddenly stop
                  kglad Adobe Community Professional & MVP

                  it applies to all variables.  anything you prefix with var within a function body is local to that function and cannot be referenced outside the function and is subject to gc when the function completes its code.

                  • 6. Re: Why banner animation suddenly stop
                    tomazsr Level 1

                    Yes, I understand this but still dont get it way animation stop.

                    • 7. Re: Why banner animation suddenly stop
                      kglad Adobe Community Professional & MVP

                      that's the result of flash housekeeping:  when a tween is gc'd the code it caused to execute (an enterframe loop) is terminated.