19 Replies Latest reply on Aug 19, 2009 11:44 AM by NSurveyor

# scroll movieclip at 2x the speed as it currently is

Hi!

I have 2 buttons that are currently scrolling a movie clip with this function on(rollover):

function moveMC(end, dir) {
mc.onEnterFrame = function() {
if (Math.abs(mc._x-end)>1) {
mc._x += dir*step;
} else {
mc._x = end;

}
};
}

How is it possible to get get it to scroll at 2x that speed on(press)  ?

Thanks for the assistance

• ###### 1. Re: scroll movieclip at 2x the speed as it currently is

double step or double your swf's frame rate.

• ###### 2. Re: scroll movieclip at 2x the speed as it currently is

no, I think I need to create a new function for on press.  there has to be 2 different speeds.  one when you roll over the button and a faster speed when you press on the button.

i just need to figure out the second function of how to double the speed.

any ideas? i'm guessing it's not like algebra that I can just put a 2 in front of the parenthesis?

• ###### 3. Re: scroll movieclip at 2x the speed as it currently is

function moveMC(end, dir, step) {
mc.onEnterFrame = function() {
if (Math.abs(mc._x-end)>1) {
mc._x += dir*step;
} else {
mc._x = end;

}
};
}

• ###### 4. Re: scroll movieclip at 2x the speed as it currently is

Wow this works perfect!  Just curious, not an actionscript pro, but what is your though process when you figured to add "step". Step is just a variable name, and since you multiplied it, it just makes it faster...?

Thanks so much, your're awesome!

• ###### 5. Re: scroll movieclip at 2x the speed as it currently is

step contrls the speed of scrolling.  that was in your original code.

i just added step as a parameter that you could pass when calling moveMC() so you could specify the scrolling speed when moveMC() is called.

• ###### 6. Re: scroll movieclip at 2x the speed as it currently is

This is the code that I have for the left arrow button that moves the movieclip.  I think I'm missing something

Because when I add the function that you posted which I named (moveMC2), the movieclip doesn't stop scrolling when I hold the onPress....? Any ideas?  The on press function has the end value, but I'm not seeing why it doesn't stop.  It stops when you do the rollover though..?

left.onRollOver = function() {

moveMC(-2410,-1);

/*if(_root.mc._x > -672){

moveMC(-660,-1);

}else if(_root.mc._x == -660){

trace("done")

}

*/

};

left.onRollOut = function() {

delete mc.onEnterFrame;

};

left.onPress = function() {

moveMCTwo(-2410,-1,20);

};

left.onRelease = function() {

moveMC(-2410,-1);

};

• ###### 7. Re: scroll movieclip at 2x the speed as it currently is

moveMC() takes 3 parameters.

• ###### 8. Re: scroll movieclip at 2x the speed as it currently is

This is the moveMC() function that I have in my project:

function moveMC(end, dir) {

mc.onEnterFrame = function() {

if (Math.abs(mc._x-end)>1) {

mc._x += dir*step;

} else {

mc._x = end;

}

};

}

It seems like it only has 2 parameters?

• ###### 9. Re: scroll movieclip at 2x the speed as it currently is

you're going backwards.

i gave you the code for a function that allows you to control the scroll speed.  it has 3 parameters.

• ###### 10. Re: scroll movieclip at 2x the speed as it currently is

Ok, I updated the code to just have the function that you gave me.  All of the on(press) functions have 3 parameters but now when you hold down the on(press), the movie clip doesn't stop at the end parameter like it used to?

Do you see what I mean by looking at the code below?

function moveMC(end, dir, step) {

mc.onEnterFrame = function() {

if (Math.abs(mc._x-end)>1) {

mc._x += dir*step;

} else {

mc._x = end;

}

};

}

/*function moveMCTwo(end, dir, step) {

mc.onEnterFrame = function() {

if (Math.abs(mc._x-end)>1) {

mc._x += dir*step;

} else {

mc._x = end;

}

};

}

*/

left.onRollOver = function() {

moveMC(-2410,-1, 5);

/*if(_root.mc._x > -672){

moveMC(-660,-1);

}else if(_root.mc._x == -660){

trace("done")

}

*/

};

left.onRollOut = function() {

delete mc.onEnterFrame;

};

left.onPress = function() {

moveMC(-2410,-1,20);

};

left.onRelease = function() {

moveMC(-2410,-1, 5);

};

right.onRollOver = function() {

moveMC(488.15,1, 5);

};

right.onRollOut = function() {

delete mc.onEnterFrame;

};

right.onPress = function() {

moveMC(488.15,1,20);

};

right.onRelease = function() {

moveMC(488.15,1, 5);

};

• ###### 11. Re: scroll movieclip at 2x the speed as it currently is

you're increasingly likely to over-step your end-condition check as step increases past 1.

use:

function moveMC(end, dir, step) {

mc.onEnterFrame = function() {

if ((dir>0&&mc._x<end)||(dir<0&&mc._x>end)) {

mc._x += dir*step;

} else {

mc._x = end;

}

};

}

• ###### 12. Re: scroll movieclip at 2x the speed as it currently is

Wow, that really works great.  Thanks for sticking with this problem!

• ###### 13. Re: scroll movieclip at 2x the speed as it currently is

you're welcome.

• ###### 14. Re: scroll movieclip at 2x the speed as it currently is

Oops....one more question.  It seems like when you scroll to the right and left and get to the end, it does a little bounce.  It doesn't come to a complete stop but moves back and forth and then stops...?  Any ideas why?

• ###### 15. Re: scroll movieclip at 2x the speed as it currently is

While kglad's last installment will stop overstepping the end-conditions for the most part, there can be a small issue at the end.

A simpler example to look at would be the following:

```r=0;
while(1){
if(r<12){
r+=5;
trace(r);
}else{
r=12;
trace(r);
break;
}
}
```

While we want r to go from 0 to 12 in steps of 5, we end up getting 0, 5, 10, 15, (and now that the condition is finally realised), 12. And this is where the bounce occurs. To remedy, simply test the to-be value of your variable in the condition instead of the variable itself. In the above case, you would use "r+5 < 12" as opposed to just "r<12".

So in your case, the following should work:

```function moveMC(end, dir, step) {
mc.onEnterFrame = function() {
if((dir>0&&mc._x+dir*step<end)||(dir<0&&mc._x+dir*step>end)) {
mc._x += dir*step;
}else {
mc._x = end;
}
};
}

```
• ###### 16. Re: scroll movieclip at 2x the speed as it currently is

Wow, that's absolutely perfect!  Thank you for your help and the explaination!

• ###### 17. Re: scroll movieclip at 2x the speed as it currently is

No problem.

• ###### 18. Re: scroll movieclip at 2x the speed as it currently is

Do you know why the movie clip and text seem to dance and move around when the movie clip is scrolled?

• ###### 19. Re: scroll movieclip at 2x the speed as it currently is

I do not know what phenomenon you refer to. Perhaps a link to an *.swf or *.fla will help explain.