4 Replies Latest reply on Sep 3, 2009 5:16 PM by kglad

    Interval doesnt work?

    Rabel

      I am working on a slideshow piece where you would press the button once to start and press again to stop. I set the variable in the main section archslideshow="off"
      All the other variables that are in the code are being called correctly so dont worry about those. This is the code I am working with


      on(release){
      if(archslideshow=="off"){
          trace(archslideshow+ " off");
          function slideshowgo(){
          newnum=_currentframe-119+1;
          if(newnum<_root.totalArchitecture-1){
              newsection=_currentframe+1;
              cover.gotoAndPlay("close");
              trace(newsection+" is a +1");
              trace(newnum+" newnum");
          }else{
              newsection=119;
              cover.gotoAndPlay("close");
              trace(newsection+" end back to beginning");
              trace(newnum+" newnumend");
          }
          }
              newnum=_currentframe-119+1;
              if(newnum<_root.totalArchitecture-1){
                  newsection=_currentframe+1;
                  cover.gotoAndPlay("close");
                  trace(newsection+" is a +1");
                  trace(newnum+" newnum");
              }else{
                  newsection=119;
                  cover.gotoAndPlay("close");
                  trace(newsection+" end back to beginning");
                  trace(newnum+" newnumend");
          }
          archslideshow="on";
          var intervalID:Number = setInterval(slideshowgo,4000);
      }else if(archslideshow=="on"){
          trace(archslideshow+ " on");
          archslideshow="off";
          clearInterval( _root.intervalID );
      }
      }

      What is happening is that the interval is only running once (jumps to next frame) then it stops and I need to press the button twice to get it to start again.

      If I remove the archslideshow coding the slideshow works perfectly but I need to set it so that if they press the button again it stops.

      This is a sample of the trace I am getting - you'll notice I need to press the button to off to get it to start again.

      off off
      127 is a +1
      8 newnum
      on on
      off off
      128 is a +1
      9 newnum
      119 end back to beginning
      10 newnumend
      120 is a +1
      1 newnum
      121 is a +1
      2 newnum
      122 is a +1
      3 newnum
      121 is a -1
      4 newnum-1
      120 is a -1
      3 newnum-1
      on on
      off off
      121 is a +1
      2 newnum
      on on
      off off
      122 is a +1
      3 newnum
      on on


      Any help is really appreciated.

      Thanks,
      Randy

        • 1. Re: Interval doesnt work?
          Rabel Level 1

          actually what is happening is that the interval is never being called, the jump is coming from the bottom part of the code where it has the same code so that it goes as soon as you press the button.
          Any ideas why the interval is not being called.

          • 2. Re: Interval doesnt work?
            kglad Adobe Community Professional & MVP

            attached to the timeline that contains your button timeline use:

             

            var intervalID:Number;

            var tl:MovieClip=this;

             

            function slideshowgo() {
                newnum = _currentframe-119+1;
                if (newnum<_root.totalArchitecture-1) {
                    newsection = _currentframe+1;
                    cover.gotoAndPlay("close");
                    trace(newsection+" is a +1");
                    trace(newnum+" newnum");
                } else {
                    newsection = 119;
                    cover.gotoAndPlay("close");
                    trace(newsection+" end back to beginning");
                    trace(newnum+" newnumend");
                }
            }

             

            and assign your button an instance name, say btn, and on the same timeline use:

             

            btn.onRelease=function() {
                if (archslideshow == "off") {
                    trace(archslideshow+" off");
                   
                    newnum = _currentframe-119+1;
                    if (newnum<_root.totalArchitecture-1) {
                        newsection = _currentframe+1;
                        cover.gotoAndPlay("close");
                        trace(newsection+" is a +1");
                        trace(newnum+" newnum");
                    } else {
                        newsection = 119;
                        cover.gotoAndPlay("close");
                        trace(newsection+" end back to beginning");
                        trace(newnum+" newnumend");
                    }
                    archslideshow = "on";
                    clearInterval(tl.intervalID);
                    tl.intervalID = setInterval(slideshowgo, 4000);
                } else if (archslideshow == "on") {
                    trace(archslideshow+" on");
                    archslideshow = "off";
                    clearInterval(tl.intervalID);
                }
            }

            • 3. Re: Interval doesnt work?
              Rabel Level 1

              Thanks kglad, that works great. Now I need to edit the 20 different sections that will use this. Can you explain why it wasnt working before.

              • 4. Re: Interval doesnt work?
                kglad Adobe Community Professional & MVP

                you're welcome.

                 

                1.  you were inconsistant with your setInterval() names.

                2.  you were making your interval name (intervalID) local to your release function.

                3.  you were nesting a named function which is never a good idea.

                 

                if you still can, mark this thread as answered.