|In the next step, each square is given a rate of change for
x and y, and a script which executes using the onEnterFrame
event handler to update the square's position...
The basic method here is to give each square two values, dx and dy (you can think of this as meaning difference in x, difference in y). On every frame these values are added to the square's _x and _y properties. If the square travels outside a boundary, the value of dx or dy (horizontal or vertical boundary) is reversed so that the direction of travel is reversed - this causes the squares to 'bounce'.
The script to achieve this is shown on the next page...