Creating a Basic Scroller
This tutorial is useful if you want to create a scroll menu or let something move by using buttons. First you need to create a button. In our case the button is invisible and has only a hitarea. Then you need to have the thing to scroll, which is a movieclip here. You have to determine the coordinates for the right end and left end of your movie. Then give all your clips names. Here I called the button but1 and the ball circle. Now we have to make the ball move in a controlled way. Look at the script below. We first create a function and call it circleMove(speed). We create a var and call it m and set m to 0. m is useful to toggle between if functions.
function circleMove(speed)
{
var m = 0;
circle.onEnterFrame = function()
{
if (m == 0 && this._x<450)
{
this._x += speed;
}
else if (this._x>=450 || this._x>4)
{
this._x -= speed;
m = 1;
}
else if (this._x<=4)
{
m = 0;
}
};
}
Next we create a onEnterFrame event function. We can also use setInterval here. Now we let the ball move by our first if-statement. The border for the most right edge is 450 and the ball will stop there but we don't want the ball to stop but rather move back, which we do in the second if-statement. The - operator will reverse the direction of the move and speed is our argument and in the end a number. We have to set m to a different value here to prevent the first if statement from being executed. The last if-statement is executed when the ball at the left end and all it does is setting m back to 0. This will start the script allover.
The next parts are just the execution of the functions and simple button rollover and out functions.
but1.onRollOver = function()
{
circleMove(15);
};
but1.onRollOut = function()
{
circleMove(3);
};
circleMove(3);