Graphics Programs Reference
In-Depth Information
The file contains three layers. Layer 1 contains the background. Layer 2 has a movie
clip with an instance name of object_mc , located just off the upper left of the Stage.
Layer 3 will contain the actions needed to generate the imagery. In this exercise we
are going to duplicate a fish 25 times and randomly assign a location in 3D space to
each duplicate.
Step 1: Getting started
Let's begin by setting up some information about our 3D world. Enter the script below
in the actions layer. In line 2 we are defining the viewer distance to be 200. Although
the units of measurement can be anything you want as long as they are consistent, it
is usually easiest to think in terms of pixels.
In lines 6 and 7, we set the center of the Stage to be the origin (xo,yo) of the screen
coordinates, which also serves as the origin of the 3D coordinate system. Positive and
negative values of x and y will be measured from that point.
1
2
3
4
5
6
7
8
// set the viewer distance d from the screen
var d:Number = 200;
// set the center of the stage xo, yo as the origin
// of the screen coordinates
var xo:Number = Stage.width/2;
var yo:Number = Stage.height/2;
Step 2: Create the objects
Next let's make some copies of the fish. In line 10 we are setting the number of dupli-
cated fish to be 25. The actual duplication process is given in lines 13-19. The for loop
states that the steps inside the loop are to be repeated beginning with i=0 and with i
incremented by 1 ( i++ ) for as long as i is less than numObjects . Thus i will take on
the values 0, 1, 2, ..., and 24.
Line 15 duplicates the fish movie clip for each value of i , creating movie clips named
“object0”, “object1”, “object2”, and so on, up to “object24”, with each ball on its own
separate depth level 0, 1, 2, ..., and 24.
In line 13 we are defining the variable thisObj , which will temporarily hold the name
of each duplicated fish. If you are not familiar with the notation, it may seem a little
Search WWH ::




Custom Search