3 Replies Latest reply: Mar 30, 2012 2:54 PM by kglad RSS

    Flash file will occasionally ignore Actionscript 2

    Gamera_Jr

      I have some touchscreens I maintain at work, we use Flash with Actionscript 2 to display the content. The touchscreens display a series of images as a screensaver, then when you touch the screen it goes to the main menu. Occasionally when you touch the screen, the file will then start simply going through every frame in the file in order and ignoring all the actionscript. I can't tell if this is a hardware or scripting issue, since I can't reproduce it with any regularity, but it happens often enough to be annoying. It definitely seems to happen in the transition between screensaver loop and the main menu.

       

      The screensaver button script is simply:

      on (release)

      {

          gotoAndPlay ("Bumper");

      }

       

      The menu menu and every section of content has script like this:

      stop();

       

      //number of second to wait before going to screensaver

      //var secondsToWait = 40;

       

       

      //converts milliseconds to seconds;

      var duration = 1000 * _global.timeToWait;

      var inv;

       

      // the function to activate the screensaver (go to frame 1 or "slideshow")

      // and clear the interval

      function screensaver() {

      clearInterval(inv);

      gotoAndPlay("screensaver");

      }

       

      //sets the interval to run the screensaver function every 40 seconds(1000ms * 4 = 40 seconds)

      function inactive(){

      inv = setInterval(this,"screensaver", duration);

      }

       

      function reset(){

          clearInterval(inv);

      }

       

      //clears previous timer

      reset();

       

       

      //calls the inactive function.

      inactive();

       

      Any idea what might be doing this?

        • 1. Re: Flash file will occasionally ignore Actionscript 2
          kglad MVP

          a failure to clear all intervals.

           

          always clear intervals before setting them to ensure there are no run-away intervals.

          • 2. Re: Flash file will occasionally ignore Actionscript 2
            Gamera_Jr Community Member

            I'm still new to coding Actionscript, but which interval isn't getting cleared?

             

            If I'm reading the script right it calls the reset function to clear the interval before setting it with the inactive function.

            • 3. Re: Flash file will occasionally ignore Actionscript 2
              kglad MVP

              if that frame (or those frames) play before an interval is cleared, the interval in inactive() is apt to never be cleared.  use:

               

              stop();

               

              //number of second to wait before going to screensaver

              //var secondsToWait = 40;

               

               

              //converts milliseconds to seconds;

              var duration = 1000 * _global.timeToWait;

              var inv;

               

              // the function to activate the screensaver (go to frame 1 or "slideshow")

              // and clear the interval

              function screensaver() {

              clearInterval(inv);

              gotoAndPlay("screensaver");

              }

               

              //sets the interval to run the screensaver function every 40 seconds(1000ms * 4 = 40 seconds)

              function inactive(){

              clearInterval(inv);  // always clear the interval before setting.  ie, every setInterval() should be preceded by a clearInterval()

              inv = setInterval(this,"screensaver", duration);

              }

               

              function reset(){

                  clearInterval(inv);

              }

               

              //clears previous timer

              reset();

               

               

              //calls the inactive function.

              inactive();