Graphics Programs Reference
In-Depth Information
Step 2: Create a placeholder for z-values
We are going to be temporarily changing the z-values of the selected flag in order to
have it zoom in. When we click on a new flag, we want the previous flag to return to its
original z-value. In order to do this, we need to have a placeholder to store the z-value.
A convenient place to do this is in the zdata array. We'll just tack on an extra element
in the array that is initially set to 0. Add the two lines shown below.
30
31
32
33
34
35
36
37
38
zdata[i-1] = 800 + 1000*Math.random(); // 800 < z < 1800
placeObj();
}
// add a placeholder to store z-value of selected flag
zdata[numberOfObjects] = 0;
// place an object in 3D space
function placeObj()
Step 3: Initialize zoom in variables
We need to define several variables that will be required to enable us to zoom a flag.
The zoomIn variable will be used in the onEnterFrame handler to determine whether
to zoom in or not. It has a value of either true or false.
When the user clicks on a flag, we will have to store which flag is selected and the
depth that the flag is at. This information is stored in mySelection , which is initialized
to 0, and myDepth , which starts at a ridiculously low number of -30,000 to avoid any
conflicts with actual depth values. Finally, we define a variable prevId , which will hold
the flag number of the previously selected flag so that we can reset its z-value after
zooming in. Insert the lines shown.
88
89
90
91
92
93
94
95
96
97
// -----------------------------------------------------------
// define the scene and background actions
// initialize variables needed to zoom a flag
var zoomIn:Boolean = false; // to zoom or not to zoom
var mySelection:Number = 0; // current selected flag number
var myDepth:Number = -30000; // depth of current flag
var prevId:Number = 0; // previous selected flag number
// click on a flag to move the viewer towards it
 
Search WWH ::




Custom Search