6 Replies Latest reply: Dec 25, 2011 7:02 AM by kglad RSS

    detect inactivity mouse

    anjemalo

      Hello:

       

      I have one principal menu with six buttons, each button open (in a loader) new menues flash movies, one of them flash movie, for example, has 20 buttons each button open in a loader a  new movie. I need to detect inactivity for ten minutes for example and come back to the principal menu. Do I have tu put the code in all movies or there is a way tu put only in the movie with 20 buttons?

       

      thank you very much

        • 1. Re: detect inactivity mouse
          kglad MVP

          your main swf can detect events in all loaded swfs.  so, if you wanted to detect 10min mouse inactivity, in your main swf:

           

          var t:Timer=new Timer(10000,0);

          t.addEventListener(TimerEvent.TIMER,timeoutF);

          t.start();

          this.addEventListener(MouseEvent.MOUSE_MOVE,moveF);

           

          function moveF(e:MouseEvent):void{

          t.reset();

          t.start()

          }

          function timeoutF(e:TimerEvent):void{

          // do whatever because of mouse inactivity

          }

          • 2. Re: detect inactivity mouse
            anjemalo Community Member

            Thank you very much.

            How can remove the timer when finish?

            I have used removeEventListener and don't stop the timer.

            many thanks

            • 3. Re: detect inactivity mouse
              kglad MVP

              if you no longer need the timer after one timeout, use:

               

               

              var t:Timer=new Timer(10000,0);

              t.addEventListener(TimerEvent.TIMER,timeoutF);

              t.start();

              this.addEventListener(MouseEvent.MOUSE_MOVE,moveF);

               

              function moveF(e:MouseEvent):void{

              t.reset();

              t.start()

              }

              function timeoutF(e:TimerEvent):void{

              // do whatever because of mouse inactivity

              t.removeEventListener(TimerEvent.TIMER,timeoutF);

              t=null;

              }

              • 4. Re: detect inactivity mouse
                anjemalo Community Member

                Thanks again.

                I have other question:

                I am in the main swf and a second, third... swf are loaded, when the timer is over how can I remove this second, third... swf and come back to main swf?

                 

                Other one If I am in the main swf and the timer is over how can I stay in the main swf?

                 

                Many many thanks to you.

                • 5. Re: detect inactivity mouse
                  anjemalo Community Member

                  Hello:

                  I have another problem, when I load new swf and move mouse in the loaded swf the timer continue don't reset.

                  thanks

                  • 6. Re: detect inactivity mouse
                    kglad MVP

                    1.  to unload a loaded swf, apply unloadAndStop(), if you're publishing for fp10+, to the loader or unload().

                     

                    2.  to reset the timer, apply reset() to the timer.   to restart the timer, apply start() to the timer.  both are showing in moveF()