17 Replies Latest reply on Feb 26, 2007 2:47 PM by Seraya

    Need movieclip to move up and down

    Seraya Level 1
      Hi everyone,

      I have a movieclip on the main timeline and would like it to move very slowly up and down on a continuous basis. I'd like to use actionscript to do this instead of tweening on the timeline. The only actionscript I can think of that might work is using the _y property but I don't know how to construct the full actionscript to make it work. Can someone help out?

      Thanks for any help offered.
        • 1. Re: Need movieclip to move up and down
          Sketchsta Level 1
          Hi Seraya, u can use setInterval to repeat the _y position of your movieClip, with if statements to make it decrease it's _y position.

          eg...

          if(mc._y<400){
          mc._y += 1;}
          else{
          mc._y -= 1;}

          something like that in a function, then just call it onEnterFrame.
          • 2. Re: Need movieclip to move up and down
            Seraya Level 1
            Thanks for the reply. I used the following code after your example:

            function move()
            { if(bizServices_mc._y<60){
            bizServices_mc._y += 1;}
            else{
            bizServices_mc._y -= 1;}
            }

            _root.onEnterFrame = function() {
            move;
            };

            ... but it doesn't seem to work. You mentioned using setInterval to repeat the _y position, but setInterval isn't in the code above. Is this why it's not working and if so how would I incorporate setInterval?

            Appreciate your continued support.
            • 3. Re: Need movieclip to move up and down
              Sketchsta Level 1
              try:

              _root.onEnterFrame = function(){
              setInterval(move,5);
              }

              with setInterval you have to specify 2 params..
              1, which function to repeat (move)
              2, how often should the function repeat (5) . How often, is specified in mili-seconds. So say you wanted the function to repeat every 2 seconds, you would put 2000.
              • 4. Re: Need movieclip to move up and down
                Seraya Level 1
                Hi again,

                I've revised the code with your suggestion, but it doesn't really work as expected. The clip moves really fast down to the 60 pixel y coordinate and then it just jumps about 1 pixel up and down at the point continously - no smooth motion back up to the top.

                I've uploaded the .fla to this address:

                http://www.officelinkonline.com.au/file

                Would you mind taking a quick look to see what I might have done wrong?
                • 5. Re: Need movieclip to move up and down
                  Sketchsta Level 1
                  ahh yes, I see whats going on.. I should have been abit more specific. oops!! =)
                  you needed to make the Intervals clear, and call a new interval when it reaches a destination.

                  just replace the code you have with this code, and you should have no problems..
                  but just out of curiosity....why would you want a text field to move up and down??? makes it hard to read and scroll through the text.. unless thats the whole idea... anyway, if thats the whole idea, I Like It!! =P I play jokes sometmes too..

                  • 6. Re: Need movieclip to move up and down
                    Seraya Level 1
                    Thanks again. All code is working great. I slowed down the movement to .08 so it's a gentler move. It's probably a dumb idea to have the text moving but I thought it'd make things a bit more interesting. I thought though, just in case it cheeses people off too much, I could have a RollOver happening where the movieclip could jump to a stationery coordinate when the mouse rolls over the clip. I tried:

                    bizServices_mc.onRollOver = function () {
                    this.bizServices_mc._y = 55;
                    }

                    ... but no luck. I'm guessing I need to clear the currently active function and then set the clip's y coordinate to 55 as above. Then I'd need an onRollOut which invoked repeatUp:Number - setInterval (moveUp, 5) to get the movement happening again.

                    Again I'm not sure how to put the code together correctly - can you help with this last bit of code?
                    • 7. Need movieclip to move up and down
                      Sketchsta Level 1
                      on rollOver, you dont have to set it to a specific location... you can simply clearInterval, and it will stop.
                      eg...

                      bizServices.onRollOver = function(){
                      clearInterval(repeatUp);
                      clearInterval(repeatDn);
                      //if you want bizServices to goto a certain spot tho. use...
                      //bizServices._y = 55;
                      }

                      because the intervals are changing every second or so, we dont know when the user will rollOver bizServices...during repeatUp, or repeatDn...
                      so we just clear both.. =)

                      and t start it up again... you're absolutely right. =)

                      bizServices.onRollOut = function(){
                      repeatDn = setInterval(moveUp,5);
                      }

                      would do the trick..
                      • 8. Re: Need movieclip to move up and down
                        Seraya Level 1
                        Thanks - everything's working perfectly - except for one thing. When the onRollOver happens and the clip stops, I'm not able to use the scroll bar to scroll the text box. Any way to remedy this?
                        • 9. Re: Need movieclip to move up and down
                          Sketchsta Level 1
                          hmm, yeah i see what you mean... this is happening because of the rollOver and rollOut functions, the whole movieClip is treated like a button...

                          I havent thought of that...

                          I'll work on it tonight, and should have something for you by tomorrow. k!!
                          got visitors at the moment...cant leave them alone!! =)
                          • 10. Re: Need movieclip to move up and down
                            SymTsb Level 2
                            I'd honestly recommend using the Tween class and then it's completion handler with a yoyo command to do this. it takes a lot less code and it doesn't use the buggy setInterval command.
                            • 11. Re: Need movieclip to move up and down
                              Seraya Level 1
                              I haven't used the Tween class before, but I thought I'd start off like this:

                              new mx.transitions.Tween(bizServices_mc, "_y", mx.transitions.easing.Elastic.easeOut, 5, 61, 3, true)

                              Any chance of providing the rest of the code - the completion handler you mentioned and the "yoyo" command to get it working?
                              • 12. Need movieclip to move up and down
                                Seraya Level 1
                                Hi again,

                                I've come a bit further with the tween class and have used the following code:

                                import mx.transitions.Tween;
                                import mx.transitions.easing.*;
                                var move:Tween = new Tween(bizServices_mc, "_y", None.easeInOut, 5, 61, 10, true);
                                move.onMotionFinished = function() {
                                this.yoyo();
                                };

                                bizServices_mc.onRollOver = function() {
                                move.stop();
                                }

                                bizServices_mc.onRollOut = function() {
                                move.resume();
                                }
                                I've only had limited success though. The clip moves up and down but it's still very jerky - nothing like the smooth movement I was getting when using the setInverval code above. Also the original problem still remains when I rollover the clip and the ScrollPane scrolling doesn't work. Does anyone know what the problem might be?

                                Would really appreciate any further help to clear all this up if possible.
                                • 13. Need movieclip to move up and down
                                  SymTsb Level 2
                                  if you want movement similar to the setInterval code, you really need to provide a null to your tween object. I've had limited success using None.whatever. I've found it easier to simply go with null here. You'd think that providing none would be the same but for whatever reason unbeknown to me, it isn't so.

                                  As for the scroll pane problem.... Where is the scroll pane? Is it part of the object targeted by the onRollOver? If so, move it so that it is one level above that timeline. This way, it won't be effected by the event handlers of the moving object and therefore target-able by AS to provide it's functionality.
                                  • 14. Re: Need movieclip to move up and down
                                    Seraya Level 1
                                    I've just changed this line of code to include the null you're talking about:

                                    var move:Tween = new Tween(bizServices_mc, "_y", null, 5, 61, 10, true);

                                    It's still really choppy though. Also the scroll pane is part of the object targetted, ie. "bizServices_mc". Since the clip is moving, doesn't the scrollpane still need to stay nested within this clip so it moves with the clip? I'm not sure I understand when you say to move the scroll pane one level above that timeline - could you clarify?

                                    I've uploaded the revised file if it helps to take a look:

                                    http://www.officelinkonline.com.au/file

                                    Thanks again
                                    • 15. Re: Need movieclip to move up and down
                                      Sketchsta Level 1
                                      Hi Seraya, try this, it's not the most conventional way to use flash.. but it does the job.. plus my actionscripting isn't good enough yet, so i find silly ways to get things to work the way i need, until I learn something better. =)

                                      I had this done for the setInterval code i gave you, and to be honest I think the Tween method would be easier to use, but i don't know it verry well.
                                      So i thought SymTsb would be more help to you.

                                      but if this project of yours is in a hurry, you can use this unconventional method, until you get something better.

                                      your FLA is HERE
                                      • 16. Re: Need movieclip to move up and down
                                        SymTsb Level 2
                                        The choppy animation is a result of the short distance traveled in the 10 seconds you've set in your tween animation. The longer the tween and the shorter the distance, the more chiseled the animation is going to look. Try a shorter tween time. With such a short distance to travel, I'd think that 5 seconds would be more than enough.

                                        About the other issue with event handlers....

                                        Having looked at the movie now, I'd say that your best bet is to place an invisible movie clip directly over the top of your text inside this clip. Attach your stop and resume actions to this movie clip rather than the actual entire clip. This will allow you to have control over your scroll pane components.
                                        • 17. Re: Need movieclip to move up and down
                                          Seraya Level 1
                                          Thanks so much to you both - it's working great now!