9 Replies Latest reply on Jan 7, 2010 11:40 PM by kglad

    ScrollBar

    Sreelash Level 1

      Hi, I am trying to implement a scrollbar. I have given functionality for the scrollbar when the slider moves. But i am not able to give functionality for the up and down button of scrolbar. Can anybody help me. I tried with the following ways for giving functionality to up and down butto of scrollbar.

       

      var intervalId:Number;
      var duration:Number = 10;

       

      function loadScrollBar(){
          var up:MovieClip = scrlBarHldr.createEmptyMovieClip("up",0);
          up.attachMovie("upBtn","upBtn",0);   
          upBtnHt = up._height;
         
          var slider:MovieClip = scrlBarHldr.createEmptyMovieClip("slider",1);
          slider.attachMovie("sliderBtn","sliderBtn",0,{_height:10});
          slider._x = 0.5;
          slider._y = up._height;       
         
          var down:MovieClip = scrlBarHldr.createEmptyMovieClip("down",2);
          down.attachMovie("downBtn","downBtn",0);
          downBtnHt = down._height
          down._y = scrlBarHt - downBtnHt;
          scrlBarHldr._x = offerList._width;
         
          slider.onPress = StartDrag;
          slider.onRelease = slider.onReleaseOutside = StopDrag;
          slider.onMouseMove = MouseMove;
          up.onPress = scrolDown;
          down.onPress = scrolUp;

      }

       

      function scrolUp(){
          intervalId = setInterval(this, "executeScrlUp", duration);   
      }


      function executeScrlUp():Void{
          trace("gd")
          //scrlBarHldr.slider._y = scrlBarHldr.slider._y + 1;
      }

       

      When i tried with the above way, the timer is not getting start. Is there any other way to implement the up and down button of scrollbar.

      Otherwise please help me to find out the problem with the timer that i used.

       

      thanks and regards,

      Sreelash.

        • 1. Re: ScrollBar
          kglad Adobe Community Professional & MVP

          try:

           


              down.onPress = function(){

          clearInterval(intervalId);

          intervalId = setInterval(this, "executeScrlUp", duration);   

          }

              down.onRelease=down.onReleaseOutside = function(){

          clearInterval(intervalId);

          }


          function executeScrlUp():Void{
              trace("gd")
              scrlBarHldr.slider._y = scrlBarHldr.slider._y + 1;
          }

          • 2. Re: ScrollBar
            Sreelash Level 1

            Hi kglad, I had modified the code as following. Still when i press on the down arrow, the timer is not getting started.

             

            var autoScrlTimer:Number;
            var scrlTimer:Number;

             

            mainMC.tween(["_alpha"],100,2,"easeInOutSine",0,startScrolling);

             

            function startScrolling(){
                autoScrlTimer = setInterval(this,"automaticScroll",duration);
            }

             

            function loadScrollBar(){
                scrlBarHldr._x = offerList._x + offerList._width;
                var up:MovieClip = scrlBarHldr.createEmptyMovieClip("up",0);
                up.attachMovie("upBtn","upBtn",0);
                var down:MovieClip = scrlBarHldr.createEmptyMovieClip("down",1);
                down.attachMovie("downBtn","downBtn",1);
                down._y = Height - down._height;
               
                down.onPress = function(){
                    clearInterval(autoScrlTimer);
                    offerList.stopTween();
                    autoScrlTimer = setInterval(this,"scrollUp",10);
                }
                down.onRelease = down.onReleaseOutside = function(){
                    clearInterval(autoScrlTimer);
                }
            }

             

            function scrollUp(){
                trace("gd");
                offerList._y = offerList._y - 1;
            }

             

            First time the timer is starting and autoscrolling is working. But when the down arrow is pressed, the autoScrlTimer is not getting started. Can you help me. Because of this issue, i can't go ahead. Please reply me as soon as possible, if u have time.

             

            Thanks and regards,

            Sreelash

            • 3. Re: ScrollBar
              kglad Adobe Community Professional & MVP

              what do you mean by, .."First time the timer is starting and autoscrolling is working."?

              • 4. Re: ScrollBar
                Sreelash Level 1

                When the scrolling content is loaded, i start the timer for the scrollling to start. Then the timer is working. But when the down arrow is pressed, i clear the timer and start the timer with another function, thus its not working.

                 

                Regards,

                Sreelash

                • 5. Re: ScrollBar
                  Sreelash Level 1

                  Hi kglad,

                   

                  I make it working.

                   

                  Regards,

                  Sreelash

                  • 6. Re: ScrollBar
                    kglad Adobe Community Professional & MVP

                    great.

                     

                    please mark this thread as answered, if you can and post your code that works in case someone else has a similar problem.

                    • 7. Re: ScrollBar
                      Sreelash Level 1

                      Hi kglad,

                       

                      The changes that i have made is with bold letters.

                       

                      var autoScrlTimer:Number;
                      var scrlTimer:Number;

                       

                      mainMC.tween(["_alpha"],100,2,"easeInOutSine",0,startScrolling);

                       

                      function startScrolling(){
                         autoScrlTimer = setInterval(automaticScroll,duration);
                      }

                       

                      function loadScrollBar(){
                          scrlBarHldr._x = offerList._x + offerList._width;
                          var up:MovieClip = scrlBarHldr.createEmptyMovieClip("up",0);
                          up.attachMovie("upBtn","upBtn",0);
                          var down:MovieClip = scrlBarHldr.createEmptyMovieClip("down",1);
                          down.attachMovie("downBtn","downBtn",1);
                          down._y = Height - down._height;
                         
                          down.onPress = function(){
                              clearInterval(autoScrlTimer);
                              offerList.stopTween();
                              scrlTimer= setInterval(scrollUp,10);
                          }
                          down.onRelease = down.onReleaseOutside = function(){
                              clearInterval(scrlTimer);
                          }
                      }

                       

                      function scrollUp(){
                          trace("gd");
                          offerList._y = offerList._y - 1;
                      }

                      • 8. Re: ScrollBar
                        Sreelash Level 1

                        Hi kglad,

                         

                        The changes that i have made is with bold letters.

                         

                        var autoScrlTimer:Number;
                        var scrlTimer:Number;

                         

                        mainMC.tween(["_alpha"],100,2,"easeInOutSine",0,startScrolling);

                         

                        function startScrolling(){
                           autoScrlTimer = setInterval(automaticScroll,duration);
                        }

                         

                        function loadScrollBar(){
                            scrlBarHldr._x = offerList._x + offerList._width;
                            var up:MovieClip = scrlBarHldr.createEmptyMovieClip("up",0);
                            up.attachMovie("upBtn","upBtn",0);
                            var down:MovieClip = scrlBarHldr.createEmptyMovieClip("down",1);
                            down.attachMovie("downBtn","downBtn",1);
                            down._y = Height - down._height;
                           
                            down.onPress = function(){
                                clearInterval(autoScrlTimer);
                                offerList.stopTween();
                                scrlTimer= setInterval(scrollUp,10);
                            }
                            down.onRelease = down.onReleaseOutside = function(){
                               clearInterval(scrlTimer);
                            }
                        }

                         

                        function scrollUp(){
                            trace("gd");
                            offerList._y = offerList._y - 1;
                        }

                         

                        Kglad, when i removed the "this" parameter from the setInterval(), it got worked. Can you tell me the difference, when "this" parameter of setInterval is using or not.

                         

                        Thanks and regards,

                        Sreelash

                        • 9. Re: ScrollBar
                          kglad Adobe Community Professional & MVP

                          when the 2nd parameter of setInterval() is a string, the first parameter in setInterval() defines the scope of the called function.  when 'this' is used the scope is the same as the scope that contains the setInterval() function.

                           

                          the easiest way to get familiar with setInterval() used with a string for the 2nd parameter and non-string, is to use:

                           

                          trace(this);

                           

                          in the function body that's referenced by setInterval().

                          1 person found this helpful