36 Replies Latest reply on Jun 5, 2010 4:32 AM by ellieellis

    How to adjust the frame number in this script?

    ellieellis

      I have a timeline slider part to my animation which starts at frame 1089 and ends at frame 1173, I have a script which allows me to do this and works perfectly when I build it in a new flash file starting at frame 1, I need this code to work for the animation I have built at frame 1089, I dont know which number "1's" in the script relate to the frame number, I have tried changing them all to 1089 but that doesn't work! at the moment as soon as I click on this it jumps back to frame number 1 - which I believe as the code stands is exactly what it should be doing. Please could anyone edit this code so that it realises which frames I want it to work in?  Thank you in anticipation, Ellie x

       

      var numOfFrames:Number = 84; // number of frames in the timeline to scrub

      var widthOfScrubber:Number = 500; // width in pixels of scrubber bar

      var widthOfScrubberSlider:Number = 25; // width in pixels of scrubber slider

       

      var widthOfScrub:Number = widthOfScrubber - widthOfScrubberSlider;

      var stepValue:Number = Math.round(widthOfScrub / numOfFrames);

      var scrubX:Object = scrubber.scrubberSlider;

      var isPlaying:Number = 1;

      var home = this;

       

      scrubX._x = 0;

       

      onEnterFrame = function() {

      if (scrubber.activeNow == 1 && isPlaying == 0) {

      var frameNum = Math.round(scrubX._x / stepValue);

      gotoAndStop(frameNum);

      } else if (scrubber.activeNow == 1 && isPlaying == 1) {

      var frameNum = Math.round(scrubX._x / stepValue);

      gotoAndPlay(frameNum);

      } else if (scrubX._x <= widthOfScrub && scrubber.activeNow != 1 && isPlaying == 1) {

      scrubX._x = scrubX._x + stepValue;

      } else {

      isPlaying = 0;

      }

      }

       

      playBTN.onRelease = function() {

      scrubber.activeNow = 0;

      isPlaying = 1;

      home.play();

      }

       

      pauseBTN.onRelease = function() {

      scrubber.activeNow = 0;

      isPlaying = 0;

      home.stop();

      }

       

        • 1. Re: How to adjust the frame number in this script?
          kglad Adobe Community Professional & MVP

          try:



           

          var numOfFrames:Number = 84; // number of frames in the timeline to scrub

          var widthOfScrubber:Number = 500; // width in pixels of scrubber bar

          var widthOfScrubberSlider:Number = 25; // width in pixels of scrubber slider

           

          var startFrame:Number = 1089

           

          var widthOfScrub:Number = widthOfScrubber - widthOfScrubberSlider;

          var stepValue:Number = Math.round(widthOfScrub / numOfFrames);

          var scrubX:Object = scrubber.scrubberSlider;

          var isPlaying:Number = 1;

          var home = this;

           

          scrubX._x = 0;

           

          onEnterFrame = function() {

          if (scrubber.activeNow == 1 && isPlaying == 0) {

          var frameNum = startFrame-1+Math.round(scrubX._x / stepValue);

          gotoAndStop(frameNum);

          } else if (scrubber.activeNow == 1 && isPlaying == 1) {

          var frameNum = Math.round(scrubX._x / stepValue);

          gotoAndPlay(frameNum);

          } else if (scrubX._x <= widthOfScrub && scrubber.activeNow != 1 && isPlaying == 1) {

          scrubX._x = scrubX._x + stepValue;

          } else {

          isPlaying = 0;

          }

          }

           

          playBTN.onRelease = function() {

          scrubber.activeNow = 0;

          isPlaying = 1;

          home.play();

          }

           

          pauseBTN.onRelease = function() {

          scrubber.activeNow = 0;

          isPlaying = 0;

          home.stop();

          }

           

          • 2. Re: How to adjust the frame number in this script?
            ellieellis Level 1

            That works great - in part, the slider is now actually sliding between the correct frames, however if I slide it back to the start it jumps to frame 1 and plays, if I click on the play button which I have next to the slider bar that also jumps to frame 1 and plays, can you spot in the script where it is scripted to jump back to frame 1, at no point should any action jump back to frame 1, only 1089

             

            I really appreciate your help, you are a ray of sunshine Ellie x

            • 3. Re: How to adjust the frame number in this script?
              kglad Adobe Community Professional & MVP

              :

               



               

              var numOfFrames:Number = 84; // number of frames in the timeline to scrub

              var widthOfScrubber:Number = 500; // width in pixels of scrubber bar

              var widthOfScrubberSlider:Number = 25; // width in pixels of scrubber slider

               

              var startFrame:Number = 1089

               

              var widthOfScrub:Number = widthOfScrubber - widthOfScrubberSlider;

              var stepValue:Number = Math.round(widthOfScrub / numOfFrames);

              var scrubX:Object = scrubber.scrubberSlider;

              var isPlaying:Number = 1;

              var home = this;

               

              scrubX._x = 0;

               

              onEnterFrame = function() {

              if (scrubber.activeNow == 1 && isPlaying == 0) {

              var frameNum = startFrame-1+Math.round(scrubX._x / stepValue);

              gotoAndStop(frameNum);

              } else if (scrubber.activeNow == 1 && isPlaying == 1) {

              var frameNum = startFrame-1+Math.round(scrubX._x / stepValue);

              gotoAndPlay(frameNum);

              } else if (scrubX._x <= widthOfScrub && scrubber.activeNow != 1 && isPlaying == 1) {

              scrubX._x = scrubX._x + stepValue;

              } else {

              isPlaying = 0;

              }

              }

               

              playBTN.onRelease = function() {

              scrubber.activeNow = 0;

              isPlaying = 1;

              home.play();

              }

               

              pauseBTN.onRelease = function() {

              scrubber.activeNow = 0;

              isPlaying = 0;

              home.stop();

              }

               

              • 4. Re: How to adjust the frame number in this script?
                ellieellis Level 1

                Thanks again for this,

                 

                Still experiencing the same issue with the play button, however I am not going to change this now as I have decided that I wanted a replay button somewhere on this screen so this button will now do that job! I can live without a play button exclusively for the timeline slider

                 

                Just one little issue left, when you slide the slider back to the start it is now jumping to frame 1088, it needs to stay on 1089, can you identify what may be causing this.

                 

                Thank you, you are my hero xxx

                • 5. Re: How to adjust the frame number in this script?
                  kglad Adobe Community Professional & MVP

                  your original code is screwed up.  remove your scrubX mouse listeners and  use:

                   

                  kglad wrote:

                   

                  :

                   



                   

                  var numOfFrames:Number = 84; // number of frames in the timeline to scrub

                  var widthOfScrubber:Number = 500; // width in pixels of scrubber bar

                  var widthOfScrubberSlider:Number = 25; // width in pixels of scrubber slider

                   

                  var startFrame:Number = 1089

                   

                  var widthOfScrub:Number = widthOfScrubber - widthOfScrubberSlider;


                  var scrubX:MovieClip = scrubber.scrubberSlider;

                  paramsF(scrubX,0,startFrame,widthOfScrub,startFrame+numOfFrames-1);


                  var home = this;

                   

                  scrubX._x = 0;

                   

                  scrubX.onPress=function(){

                  this.startDrag(false,0,this._y,widthOfScrub,this._y);

                  clearInterval(dragI);

                  dragI=setInterval(dragF,50);

                  }

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

                  this.stopDrag();

                  clearInterval(dragI);

                  }

                  function dragF(){

                  home.gotoAndStop(Math.round(scrubX.m*scrubX._x+scrubX.b));

                  }

                  function paramsF(mc,x1,y1,x2,y2){

                  mc.m=(y1-y2)/(x1-x2);

                  mc.b=y1-mc.m*x1;

                  }

                   

                  playBTN.onRelease = function() {

                  home.play();

                  }

                   

                  pauseBTN.onRelease = function() {

                  home.stop();

                  }

                   

                  • 6. Re: How to adjust the frame number in this script?
                    ellieellis Level 1

                    Sorry to be a pain, I really want to learn and understand but I am brand new to this, how do I go about removing my scrubX mouse listeners?

                    • 7. Re: How to adjust the frame number in this script?
                      kglad Adobe Community Professional & MVP

                      do you see anything like

                       

                      scrubX.onPress

                       

                      in your code?

                      • 8. Re: How to adjust the frame number in this script?
                        ellieellis Level 1

                        I dont think im understanding very well, I have been simply deleting my existing actionscript and replacing it entirely with the actionscript you have given me, I just tried this with the most recent code you gave me and that is not sliding through the frames, the following script which you gave me time before last works but with the slider jumping to frame 1088 when you slide back to the start of the section

                         

                        var numOfFrames:Number = 84; // number of frames in the timeline to scrub

                        var widthOfScrubber:Number = 500; // width in pixels of scrubber bar

                        var widthOfScrubberSlider:Number = 25; // width in pixels of scrubber slider

                         

                        var startFrame:Number = 1089

                         

                        var widthOfScrub:Number = widthOfScrubber - widthOfScrubberSlider;

                        var stepValue:Number = Math.round(widthOfScrub / numOfFrames);

                        var scrubX:Object = scrubber.scrubberSlider;

                        var isPlaying:Number = 1;

                        var home = this;

                         

                        scrubX._x = 0;

                         

                        onEnterFrame = function() {

                        if (scrubber.activeNow == 1 && isPlaying == 0) {

                        var frameNum = startFrame-1+Math.round(scrubX._x / stepValue);

                        gotoAndStop(frameNum);

                        } else if (scrubber.activeNow == 1 && isPlaying == 1) {

                        var frameNum = startFrame-1+Math.round(scrubX._x / stepValue);

                        gotoAndPlay(frameNum);

                        } else if (scrubX._x <= widthOfScrub && scrubber.activeNow != 1 && isPlaying == 1) {

                        scrubX._x = scrubX._x + stepValue;

                        } else {

                        isPlaying = 0;

                        }

                        }

                         

                        playBTN.onRelease = function() {

                        scrubber.activeNow = 0;

                        isPlaying = 1;

                        home.play();

                        }

                         

                        pauseBTN.onRelease = function() {

                        scrubber.activeNow = 0;

                        isPlaying = 0;

                        home.stop();

                        }

                        • 9. Re: How to adjust the frame number in this script?
                          kglad Adobe Community Professional & MVP

                          click on your subber and while it's selected check the actions panel.  is there any code?

                          • 10. Re: How to adjust the frame number in this script?
                            ellieellis Level 1

                            Okay I think im starting to understand better, there is NO code in the actions panel when I click on the scrubber.

                             

                            I tried pasting the code you suggested I replace my scrubber code with and it came back with 15 compiler errors, I cant seem to copy and paste the errors to show you though....?

                            • 11. Re: How to adjust the frame number in this script?
                              ellieellis Level 1

                              oooooh hang on, i've just gone back to the place where I got my code from originally

                              http://www.kirupa.com/forum/showpost.php?p=2387175&postcount=2

                              there is a code to paste in the scrubber, I didnt do this (didnt know it was there until your suggestion) however it doesnt like the first line of the code on the compiler - error!

                              • 12. Re: How to adjust the frame number in this script?
                                kglad Adobe Community Professional & MVP

                                how do you move your scrubber then?

                                • 13. Re: How to adjust the frame number in this script?
                                  ellieellis Level 1

                                  I dont know how/why it works, I did not see that scrubber code to paste in before tonight, now that I have tried pasting it in it doesnt seem to make any difference, im sure im probably getting it wrong or missing something important, I have the section in a separate .fla file which is just over 5mb large, (this I built in its own flash file and so starts from frame 1, therefore not having the problems of this which I want to start in frame 1089) is this file size to big to email to you? or is there a way of adding it as a file attachment to download on here? maybe if you can see what I did it would make more sense?

                                  • 14. Re: How to adjust the frame number in this script?
                                    ellieellis Level 1

                                    I just noticed that although there is no script showing in the actions panel, underneath is a tab which has a part of a cog symbol, when I right click on it it says Pin Script - does this mean the script is in someway hidden....?

                                    • 15. Re: How to adjust the frame number in this script?
                                      kglad Adobe Community Professional & MVP

                                      copy and paste the first few compiler errors.

                                      • 16. Re: How to adjust the frame number in this script?
                                        ellieellis Level 1

                                        Thank you for baring with me!

                                        Have figured out how to copy them now......These are the first few compiler errors when I paste the code you suggested:

                                         

                                        They all start with

                                        scene=scene 1, layer=layer45 (layer 45 contains the scrubber bar)

                                        Statement must appear within on/onClipEvent handler

                                         

                                        var numOfFrames:Number = 84; // number of frames in the timeline to scrub

                                        • 17. Re: How to adjust the frame number in this script?
                                          ellieellis Level 1

                                          weird I pasted 6 and now I can only see 1!!?? let me do it again....

                                          • 18. Re: How to adjust the frame number in this script?
                                            ellieellis Level 1

                                            var widthOfScrubber:Number = 500; // width in pixels of scrubber bar

                                            • 19. Re: How to adjust the frame number in this script?
                                              ellieellis Level 1

                                              and its happened again?????

                                              • 20. Re: How to adjust the frame number in this script?
                                                ellieellis Level 1

                                                var widthOfScrubberSlider:Number = 25; // width in pixels of scrubber slider

                                                • 21. Re: How to adjust the frame number in this script?
                                                  ellieellis Level 1

                                                  hahahah it only lets me do one at a time - want some more - one at a time!?

                                                  • 22. Re: How to adjust the frame number in this script?
                                                    kglad Adobe Community Professional & MVP

                                                    you attached that code to an object.

                                                     

                                                    delete all the code.  click on a frame where your scrubber exists.  in the actions panel paste the code i suggested.  retest.

                                                    • 23. Re: How to adjust the frame number in this script?
                                                      ellieellis Level 1

                                                      done this; deleted the code from the object, clicked on layer 45, on frame 1093 (or something like that) the part of the timeline where the scrubber is, pasted suggested code in actions panel, no script errors, tested movie, the slider still goes back to frame 1088 when i slide it back to the start......?

                                                      • 24. Re: How to adjust the frame number in this script?
                                                        kglad Adobe Community Professional & MVP

                                                        you probably still have code left somewhere in your project.

                                                         

                                                        to confirm, remove the code i suggested.  can you drag your scrubber?

                                                        • 25. Re: How to adjust the frame number in this script?
                                                          ellieellis Level 1

                                                          Ok I think I found it, if I double click on the scrubber bar on the stage, a new timeline appears at the top, it has 3 layers, 2 layers contain the scrubber image, one layer contains a script:

                                                           

                                                          var activeNow:Number;

                                                           

                                                          scrubberSlider.onPress = function(){

                                                          scrubberSlider.startDrag(false, 0, 0, 475, 0);

                                                          activeNow = 1;

                                                          }

                                                           

                                                          scrubberSlider.onRelease = function() {

                                                          scrubberSlider.stopDrag();

                                                          activeNow = 0;

                                                          }

                                                           

                                                          If I delete this script and replace with yours the scrubber bar no longer functions?

                                                          • 26. Re: How to adjust the frame number in this script?
                                                            kglad Adobe Community Professional & MVP

                                                            delete that code.

                                                             

                                                            what's the following trace() show:

                                                             


                                                             

                                                            var  numOfFrames:Number = 84; // number of frames in the timeline to scrub

                                                            var widthOfScrubber:Number = 500; // width in  pixels of scrubber bar

                                                            var  widthOfScrubberSlider:Number = 25; // width in pixels of scrubber slider

                                                             

                                                            var startFrame:Number = 1089

                                                             

                                                            var widthOfScrub:Number = widthOfScrubber -  widthOfScrubberSlider;


                                                            var scrubX:MovieClip = scrubber.scrubberSlider;

                                                            paramsF(scrubX,0,startFrame,widthOfScrub,startFrame+numOfFrames-1);


                                                            trace(scrubX);


                                                            var  home = this;

                                                             

                                                            scrubX._x = 0;

                                                             

                                                            scrubX.onPress=function(){

                                                            this.startDrag(false,0,this._y,widthOfScrub,this._y);

                                                            clearInterval(dragI);

                                                            dragI=setInterval(dragF,50);

                                                            }

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

                                                            this.stopDrag();

                                                            clearInterval(dragI);

                                                            }

                                                            function  dragF(){

                                                            home.gotoAndStop(Math.round(scrubX.m*scrubX._x+scrubX.b));

                                                            }

                                                            function  paramsF(mc,x1,y1,x2,y2){

                                                            mc.m=(y1-y2)/(x1-x2);

                                                            mc.b=y1-mc.m*x1;

                                                            }

                                                             

                                                            playBTN.onRelease  = function() {

                                                            home.play();

                                                            }

                                                             

                                                            pauseBTN.onRelease =  function() {

                                                            home.stop();

                                                            }

                                                            • 27. Re: How to adjust the frame number in this script?
                                                              ellieellis Level 1

                                                              Good morning,

                                                               

                                                              I just tried the new code you gave me, the slider bar does not function on test movie with this code....?

                                                              • 28. Re: How to adjust the frame number in this script?
                                                                kglad Adobe Community Professional & MVP

                                                                what's the trace output?

                                                                • 29. Re: How to adjust the frame number in this script?
                                                                  ellieellis Level 1

                                                                  Trace output is new to me, but i'm guessing it should appear in the output panel? When I test the movie all that appears in the output panel is the word: undefined

                                                                  • 30. Re: How to adjust the frame number in this script?
                                                                    kglad Adobe Community Professional & MVP

                                                                    that means you don't have a movieclip named:

                                                                     

                                                                    scrubber.scrubberSlider

                                                                     

                                                                    when that code executes.

                                                                    • 31. Re: How to adjust the frame number in this script?
                                                                      ellieellis Level 1

                                                                      So what do I need to do? Should I rename the scrubber object?

                                                                      • 32. Re: How to adjust the frame number in this script?
                                                                        ellieellis Level 1

                                                                        hmmmm just tried that idea, converted the scrubber object into a movieclip and named scrubber.scrubberSlider, but on test the scrubber doesn't function and the output result is the same.....? Lost!

                                                                        • 33. Re: How to adjust the frame number in this script?
                                                                          kglad Adobe Community Professional & MVP

                                                                          click the movieclip on the timeline that contains that code to select it.  in the properties panel you should see scrubber.  if you don't add that to assign the instance name used in your code.

                                                                           

                                                                          then go to scrubber's timeline and click the slider to select it.  in the properties panel you should see scrubber.Slider.  if not, add it.

                                                                          1 person found this helpful
                                                                          • 34. Re: How to adjust the frame number in this script?
                                                                            ellieellis Level 1

                                                                            In the code part of the timeline I have clicked on that layer on the timeline, in the 'properties' panel under the panel 'Label' next to 'name' I have written: scrubber.

                                                                            When I click on the slider control object, in the properties panel is already written scrubberSlider, i tried replacing that with scrubber.Slider. but an error box came up saying that is not a valid instance name, it can not contain certain characters etc. so left as scrubberSlider and tested movie like that, the slider still wont function at all?

                                                                            • 35. Re: How to adjust the frame number in this script?
                                                                              kglad Adobe Community Professional & MVP

                                                                              you didn't follow directions.  do you see a difference between:

                                                                               

                                                                              click the movieclip on the timeline that contains that code to select it.  in the properties panel you should see scrubber.  if you don't add that to assign the instance name used in your code.

                                                                               

                                                                              and

                                                                               

                                                                              In the code part of the timeline I have clicked on that layer on the  timeline, in the 'properties' panel under the panel 'Label' next to  'name' I have written: scrubber.

                                                                              1 person found this helpful
                                                                              • 36. Re: How to adjust the frame number in this script?
                                                                                ellieellis Level 1

                                                                                Thanks for your help, i'm not really getting it though am I!!! I guess I will have to spend a lot more time learning and will stop taking up your time, i'm sure the tutors will accept my glitch as part of my learning curve.