With the Actions panel open, select Frame 1 of the Actions layer and add the following script:
var stickStart:Number = stick._x;
var stickStop:Number = stick._x + 100;
var ballStart:Number = ball._x;
var ballStop:Number = ball._x - 350;
var isBallRolling:Boolean = false;
var rollDistance:Number = 0;
In this script we set some initial variables that we'll be using from inside our event handlers. The first four variables will help us track the positioning of the stick and ball. The first variable, named
stickStart, represents the initial position of the
stick MovieClip on the
x axis. The second variable, named
stickStop, represents the maximum position the stick can be moved on the
x axis. The third variable, named
ballStart, represents the initial position of the ball on the
x axis. The fourth variable, named
ballStop, represents the maximum distance the ball can move on the
x axis.
The fifth variable, named
isBallRolling, is a
Boolean value that represents whether the ball is currently rolling or moving. It is initially set to false, but after we hit the ball it is set to true until it has completed its move.
The final variable, named
rollDistance, is set when the ball is initially hit. As the ball moves, this value is reduced until it is less than or equal to zero. When it reaches that point, we know the move is complete.