Graphics Programs Reference
In-Depth Information
Figure 11.39 Movement of the foreground to its maximum location
When the background moves, the foreground must move relative to it, and they both
must end at the left edge of the Stage at the same time. The foreground must travel
750 pixels in the same time the background moves 350 pixels. In other words, the
foreground must travel 750/350, or 15/7 (= 2.14) times as fast as the background.
Going through a similar process for each of the layers shows how each must move
relative to the background.
As it turns out, it is easy to get the information on how far each layer moves simply
by reading its x-value in the Properties window. This value gives the distance from the
object to the origin, which is all the information we need. Since we have objects moving
around, we'll put everything inside an onEnterFrame handler. We let the mouse identify
the target we want to move toward (line 7). If the background location is less than the
target location, we just move the objects in unison according to their relative speed
factors. If the background location is greater than the target location, we just move
the objects by the same amount in the opposite direction.
There is just one piece of business to take care of. We don't want the background or
other objects to run off the Stage, either on the left or right. If the background is at
xmax , we just set it to remain at that location until the mouse is moved in the opposite
Search WWH ::




Custom Search