5 Replies Latest reply on Nov 20, 2007 4:21 PM by kglad

    actionscript 2.0 functions - Help

    bobby robo
      Hi all. Hope your all well.

      I'm having a spot of bother with some scripting. Any help would be much appreciated.

      The problem is this. I'm scripting a slide show. The slide show has three buttons. mcNextButton, mcBackButton and mcResetButton. I can get the mcNextButton to fade the images forwards when the user presses the button. But i'm having problems fading the images in reverse when the user presses the mnBackButton.

      Below is the scritpt:

      var aImages:Array = new Array(mcOne, mcTwo, mcThree, mcFour, mcFive, mcSix);
      var nIndex:Number = 0;
      var nInterval:Number;

      mcNextButton.onRelease = function():Void{
      clearInterval(nInterval);
      nInterval = setInterval(fadeImageForwards, 20, aImages[nIndex] )
      };

      mcBackButton.onRelease = function():Void {
      clearInterval(nInterval);
      nInterval = setInterval(fadeImageBackwards, 20, aImages[nIndex])
      };

      mcResetButton.onRelease = function():Void {
      for(var i:Number = 0; i < aImages.length; i++){
      aImages ._alpha = 100;
      };
      nIndex = 0;
      };

      function fadeImageForwards(mcImage:MovieClip):Void{
      mcImage._alpha -= 20;
      if(mcImage._alpha <= 0){
      clearInterval(nInterval);
      nIndex++;
      };
      updateAfterEvent;
      };

      function fadeImageBackwards(mcImage:MovieClip):Void{
      mcImage._alpha -= 20;
      if(mcImage._alpha <= 0){
      clearInterval(nInterval);
      nIndex--;
      };
      updateAfterEvent;
      };

        • 1. Re: actionscript 2.0 functions - Help
          Greg Dove Level 4
          Its easier if you use the attach code button to post code here... otherwise it can lose parts of it, like what happened there.

          I think your updateAfterEvents are missing the parentheses:
          updateAfterEvent();

          And (without checking too deeply) your fadeImageBackwards should probably be more like this:
          function fadeImageBackwards(mcImage:MovieClip):Void{
          mcImage._alpha += 20;
          if(mcImage._alpha >= 100){
          clearInterval(nInterval);
          nIndex--;
          };
          updateAfterEvent();
          };

          • 2. Re: actionscript 2.0 functions - Help
            bobby robo Level 1
            Hi thanks for that. V helpful
            • 3. Re: actionscript 2.0 functions - Help
              Greg Dove Level 4
              No problems. You're welcome
              • 4. Re: actionscript 2.0 functions - Help
                bobby robo Level 1
                hi there again.

                If you could help me trouble shoot a certain problem that would be v helpful. The script works fine. Although i've noticed this:

                if i scroll through the images using the mcNextButton then click on the mcBackButton to scroll through the images in reverse. I have to click the mcBackButton twice before it starts to scroll in reverse. Its almost like the first click activates the button and the secong click allows you to scroll.

                I've attached the code using 'Attach code' but just in case that doesn't work here it is again.

                var aImages:Array = new Array(mcOne, mcTwo, mcThree, mcFour, mcFive, mcSix);
                var nIndex:Number = 0;
                var nInterval:Number;


                mcNextButton.onRelease = function():Void {
                clearInterval(nInterval);
                nInterval = setInterval(fadeImageForwards, 20, aImages[nIndex]);
                };

                mcBackButton.onRelease = function():Void{
                clearInterval(nInterval);
                nInterval = setInterval(fadeImageBackwards, 20, aImages[nIndex]);
                };

                mcResetButton.onRelease = function():Void{
                for(var i:Number = 0; i < aImages.length; i++){
                aImages ._alpha = 100;
                };
                nIndex = 0;
                };

                function fadeImageForwards(mcImage:MovieClip){
                mcImage._alpha -= 20;
                if(mcImage._alpha <= 0){
                clearInterval(nInterval);
                nIndex++
                };
                updateAfterEvent();
                };

                function fadeImageBackwards(mcImage:MovieClip){
                mcImage._alpha += 20;
                if(mcImage._alpha >= 100){
                clearInterval(nInterval);
                nIndex--;
                };
                updateAfterEvent();
                };


                Many Thanks

                R

                • 5. Re: actionscript 2.0 functions - Help
                  kglad Adobe Community Professional & MVP
                  see your duplicate post.