Graphics Programs Reference
In-Depth Information
Step 2: Add the frame loop actions
Add the script below to the bottom of what you already have. In order to see the fish
swim toward us, we will need to add a frame loop for the motion. Each time we enter
the frame, we need to loop over all of the objects (line 56) and in each case, get a new
updated value for its z - coordinate (line 59), and then display the object (line 60).
53
54
55
56
57
58
59
60
61
62
// create the movement for each object
this.onEnterFrame = function()
{ // loop over the objects
for (var i:Number=0; i<numObjects; i++)
{
thisObj = _root["object"+j];
thisObj.z += thisObj.dz; // update the z-value
displayObj(); // display the object
}
}
Save your file and then test the movie. Did anything unexpected happen? If you let
the movie run long enough, what you will see is each fish getting closer to you until,
at some point, it gets too close and then flips over belly up and moves back in space
as in Figure 6.7. Why is this happening?
Figure 6.7 Result of objects moving past the viewer
Search WWH ::




Custom Search