Code Samples
Rocket Engine
Click on the example, then use the keyboard arrows to rotate the rocket.
Download the Source Files for Adobe Flash CS4
Download the Source Files for Adobe Flash CS3
About the Example
This example uses the same implementation as used in the previous example (highly recommended to understand the previous example before this one).
Here the example shows flares attached to the engine of a rocket. As in the previous example, the first thing to do is to find the 3D coordinates for the location of the flares.
The FLA
In the FLA I imported a 3D model of a rocket using the FreeSpin3D Import Engine and created an instance of it on the stage. For the flares I created a Movieclip made of images. I used the FreeSpin3D Action Script API to get the x, y and z coordinates of the flares.
The Adobe Flash CS4 Actions Layer (If using Adobe Flash CS3, see code in box below)
import FreeSpin3D.IRvFreeSpin3D;
// note: The 3d mode instance depth is set to true (at depth 0) in the FreeSpin3D Control Panel.
// the same can be set using the FreeSpin3D ActionScript API:
// my3DModel_fs.RviSetDepthSorting(true, 0);
// add the Flares MoviClip to the depth sorting space
mcRocket.my3DModel_fs.RviAddMovieClipToDepthSorting(mcRocket.Flares, 0);
// add a behavior function to the 3D model instance of the rocket
mcRocket.my3DModel_fs.RviBehaviorFunction = OnLoop;
// implemet the OnLoop behavior function
// the function will run every enter frame on the rocket instance
function OnLoop(model_fs:IRvFreeSpin3D):void {
// get the coordinates of the rear of the rocket (in stage coordinates)
var parentCoordinates = model_fs.RviModelToParent(0, 0, 150);
// set the coordinates to the engine flares MovieClip
mcRocket.Flares.x = parentCoordinates.x;
mcRocket.Flares.y = parentCoordinates.y;
mcRocket.Flares.z = parentCoordinates.z;
// adjust the engine flares to the rocket rotation
mcRocket.Flares.rotation = model_fs.RviModelOrientationZ == 0 ? 0 : 180;
}
The Adobe Flash CS3 Actions Layer
import FreeSpin3D.IRvFreeSpin3D;
// Note: The 3D model depth is set to true (at depth 0) in the FreeSpin3D Control Panel
// This can also be set by code:
// my3DModel_fs.RviSetDepthSorting(true, 0);
// Add the flares to the missile instance depth sorting space
mcMissile.my3DModel_fs.RviAddMovieClipToDepthSorting(mcMissile.Flares, 0);
// Add a function as a behavior to the missile model - names OnLoop
mcMissile.my3DModel_fs.RviBehaviorFunction = OnLoop;
function OnLoop(model_fs:IRvFreeSpin3D):void {
// Get the coordinates for the position on the flares
// The position is a bit behind the engine.
var parentCoordinates = model_fs.RviModelToParent(0, 0, 140);
// Set these coordinates to the flares
mcMissile.Flares.x = parentCoordinates[0]; // x coordinate
mcMissile.Flares.y = parentCoordinates[1]; // y coordinate
mcMissile.Flares.z = parentCoordinates[2]; // z coordinate
}

