5 Replies Latest reply on Aug 7, 2011 7:15 AM by kglad

    Cross fade frames

    Owen_Alextoys Level 1

      Hi

       

           I'm trying to cross fade between two frames using action script. I can fade a frame out with the following script but I can't figure out the cross fade part.

       

      /* Fade Out Movie Clip

      Fades out the symbol instance by decreasing its alpha property within an ENTER_FRAME event until it is invisible.

       

      Instructions:

      1. To change the speed at which the symbol instance fades out, change the 0.01 value below (valid values are in the range 0.0 - 1.0). Higher values cause faster fade out.

      2. The '-=' operator is a shortcut to typing 'Spread1.alpha = Spread1.alpha - 0.1'.

      3. Because the animation uses an ENTER_FRAME event, it progresses only when the playhead moves to a new frame, and the speed of the animation is also affected by the frame rate of the FLA file.

      */

       

      Spread1.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

      Spread1.alpha = 1;

       

      function fl_FadeSymbolOut(event:Event)

      {

      Spread1.alpha -= 0.1;

      if(Spread1.alpha <= 0)

      {

      Spread1.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

      }

      }

        • 1. Re: Cross fade frames
          kglad Adobe Community Professional & MVP

          if your object you want to fade-in has reference Spread2, use:

           


          Spread1.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

          Spread1.alpha = 1;

          Spread2.alpha = 0;

           

          function fl_FadeSymbolOut(event:Event)

          {

          Spread2.alpha+=.1;

          Spread1.alpha -= 0.1;

          if(Spread1.alpha <= 0)

          {

          Spread2.alpha=1;

          Spread1.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

          }

          }

          • 2. Re: Cross fade frames
            Owen_Alextoys Level 1

            I'm getting the following error:

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.

            at FrontDeskVideoTest_fla::MainTimeline/frame1()

             

             

            Here's the AS3:

             

            /* Stop at This Frame

            The Flash timeline will stop/pause at the frame where you insert this code.

            Can also be used to stop/pause the timeline of movieclips.

            */

             

            stop();

            var myTimer:Timer = new Timer(5000);

            myTimer.addEventListener(TimerEvent.TIMER, fiveSec);

            myTimer.start();

             

            function fiveSec(event:TimerEvent):void

            {

               this.nextFrame();

               trace(currentFrame);

            }

            Spread1.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

            Spread1.alpha = 1;

            Spread2.alpha = 0;

             

            function fl_FadeSymbolOut(event:Event)

            {

            Spread2.alpha+=.1;

            Spread1.alpha -= 0.1;

            if(Spread1.alpha <= 0)

            {

            Spread2.alpha=1;

            Spread1.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

            }

            }

            • 3. Re: Cross fade frames
              kglad Adobe Community Professional & MVP

              do you have an object Spread2 that you want to fade-in?


              • 4. Re: Cross fade frames
                Owen_Alextoys Level 1

                Yes the movie clip in the second frame is called Spread 2. I get the following in the output tab

                 

                TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at FrontDeskVideoTest_fla::MainTimeline/frame1()

                TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at FrontDeskVideoTest_fla::MainTimeline/fl_FadeSymbolOut()

                 

                Sorry for the delay

                • 5. Re: Cross fade frames
                  kglad Adobe Community Professional & MVP

                  use:

                   


                   

                   

                  /* Stop at This Frame

                  The Flash timeline will stop/pause at the frame where you insert this code.

                  Can also be used to stop/pause the timeline of movieclips.

                  */

                   

                  trace(Spread1);

                  trace(Spread2);

                   

                  stop();

                  var myTimer:Timer = new Timer(5000);

                  myTimer.addEventListener(TimerEvent.TIMER, fiveSec);

                  myTimer.start();

                   

                  function fiveSec(event:TimerEvent):void

                  {

                     this.nextFrame();

                     trace(currentFrame);

                  }

                  Spread1.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

                  Spread1.alpha = 1;

                  Spread2.alpha = 0;

                   

                  function fl_FadeSymbolOut(event:Event)

                  {

                  Spread2.alpha+=.1;

                  Spread1.alpha -= 0.1;

                  if(Spread1.alpha <= 0)

                  {

                  Spread2.alpha=1;

                  Spread1.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

                  }

                  }

                   

                   

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

                  one of both those traces are going be be null or undefined because one or both do not exist WHEN that code executes.  fix that.