0 Replies Latest reply on Nov 14, 2010 3:43 PM by iconofsin14

    fade in / out

    iconofsin14 Level 1

      Using code snippets i have made a script which fades in on mouse over and fades out on mouse out

      Once it reaches full fade in/out an if statement condition is met and the enter_frame event listener event which causes it to continue fadeing in/out is removed.

      If the mouse out is detected while it is still fading in it fully fades out and then fades back in until it reaches max fade in because when the fade out started the condition for the IF statement which removed the fade in effect had not been met.

       

      I have two questions
      1) how do i fix this (i have tried copy/pasting the removeenterframe event code for the fade in into several parts of the fade out script but all this does is stop it from working, also when i do this a second object with no script attatched to it starts flashing on and off)

       

      2) The fade in and fade out effect both operate at the same rate so if both are running one would expect the object to remain static. the way it behaves however suggests that the fade in effect is actually put on pause until the fade out effect is canceled by its own IF statement. why is this?

       

      anyway code is bellow
      --------------------------------------


      /* Fade In Movie Clip
      Fades in the symbol instance by increasing its alpha property within an ENTER_FRAME event until it is fully visible.
      Instructions:
      1. To change the speed at which the symbol instance fades in, change the 0.01 value below (valid values are in the range 0.0 - 1.0). Higher values cause faster fade in.
      2. The '+=' operator is a shortcut to typing 'movieClip_1.alpha = movieClip_1.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.
      */

       

      /* Mouse Over Event
      Mousing over the symbol instance executes a function in which you can add your own custom code.

      Instructions:
      1. Add your custom code on a new line after the line that says "// Start your custom code" below.
         The code will execute when the symbol instance is moused over.
      */

      movieClip_1.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

      function fl_MouseOverHandler(event:MouseEvent):void
      {
      movieClip_1.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_4);

      function fl_FadeSymbolIn_4(event:Event)
      {
      movieClip_1.alpha += 0.01;

      if(movieClip_1.alpha >= 1)
      {
        movieClip_1.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_4);
      }
      }
      }

      /*------------------------------------------------*/

       

      /* Mouse Out Event
      Mousing out of the symbol instance executes a function in which you can add your own custom code.

      Instructions:
      1. Add your custom code on a new line after the line that says "// Start your custom code" below.
         The code will execute when the symbol instance is moused out of.
      */

      movieClip_1.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

      function fl_MouseOutHandler(event:MouseEvent):void
      {
      movieClip_1.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);

      function fl_FadeSymbolOut(event:Event)
      {
      movieClip_1.alpha -= 0.01;
      if(movieClip_1.alpha = 0)
      {
        movieClip_1.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut);
      }

      }
      }

       

      /* 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 'movieClip_1.alpha = movieClip_1.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.
      */