|
A loader bar is used to indicate the loading progress of a Blaze 3D presentation to the user. To add this user-friendly cue to a Blaze 3D presentation, simply add the below few lines of ActionScript code to the initial frames.
ActionScript for Frame 1:
loaderBar._xscale = 0; initial = new Matrix3d(1,0,0,0,1,0,0,0,1,0,0,0)
- The _xscale variable of the loaderBar movie clip controls the x length. It is initialised at 0. The final length will be 100.
- initial is a position matrix used as the starting position that your 3D model will appear in. To specify your own position, please refer here to the section 'To Move Your Model to a Specific Position' .
ActionScript for Frame 2:
_root.renderWindow.loadMovie("blaze_3d_cube.swf"); _root.renderWindow._visible = false;
- The loadMovie function loads the 3d model “blaze_3d_cude.swf” into the renderWindow movie clip
- The _visible variable controls the visibility of the entire 3d model. The renderWindow is set to invisible.
Actionscript for Frame 3 (Frame label – “loading”):
if (renderWindow._framesloaded == renderWindow._totalframes) { loaderBar._xscale = 100; gotoAndPlay("loaded"); }
The _framesloaded variable of the renderWindow movie clip is a variable that reflects the number of frames currently loaded. The _totalframes variable of the renderWindow movie clip is a variable that is the total number of frames when the model has finished loading. Within a 3d model .swf file there is only 1 frame. So this can be used as a binary test for when the model has finished loading. When the code in line 3 is reached, the renderWindow has finished loading the 3d model “blaze_3d_cube.swf” and so the _xscale of the loaderBar movie clip is set to 100 (i.e. it is now fully loaded). And the _root movie clip skips frame 4 to frame 5 (“loaded”).
ActionScript for Frame 4:
percent= Math.round( ( 100 * renderWindow.getBytesLoaded()) / renderWindow.getBytesTotal()); loaderBar._xscale = percent; gotoAndPlay("loading");
The getBytesLoaded() function returns the number of bytes of the 3d model file that has currently been loaded into the renderWindow movie clip. The getBytesTotal() function returns the total number of bytes of 3d model file being loaded into the renderWindow movie clip. Therefore percent variable is the percentage of the 3d model file that has been loaded into the renderWindow. The _xscale of the loaderBar movie clip is set to the percent. The movie skips back to frame 5(“loading”) to test again if renderWindow has finished loading the 3d model.
ActionScript for Frame 5 (Frame label – “loaded”):
if (renderWindow.getCamera() != undefined) { gotoAndPlay("placed"); }
ActionScript for Frame 6: gotoAndPlay("loaded");
- The movie skips back to frame 5 (“loaded”) to test the camera object again.
Frame 7 (Frame label – “placed”):
cameraObj = _root.renderWindow.getCamera(); cameraObj.fieldOfView = 30; cameraObj.matrix = initial; _root.renderWindow._visible = true;
- The camera object has been defined and so variables contained in the camera object can be accessed. The fieldOfView and intial position of the camera is set. These variables have default values and so it is not necessary to set them.
- The renderWindow visibility is set to true.
|