Code Samples
Relative Movement
Click on the example, then use the keyboard arrows to rotate the plane.
Download the Source Files for Adobe Flash CS4
Download the Source Files for Adobe Flash CS3
About the Example
In this example I show how to move a object based on the movement of a 3D model instance. In the example the sky moves according to the plane direction and forward progression.
The FLA
The FLA includes a 3D model of an F-16 I imported into the stage and created a MovieClip with a background of the sky.
In the FreeSpin3D Control Panel I checked the keyboard control to true to enable the rotation of the plane by using the keyboard arrows. I converted the plane instance to a symbol and added a shadow filter (that's using the Adobe Flash filters).
Using the FreeSpin3D Action Script API I move the background based on the direction and forward progression of the plane.
The Adobe Flash CS4 Actions Layer (If using Adobe Flash CS3, see code in box below)
import FreeSpin3D.IRvFreeSpin3D;
// add a behavior function to the plane 3D model instance
plane_mc.my3DModel_fs.RviBehaviorFunction = OnLoop;
var speed:Number = 5;
var tileWidth:Number = 425;
// implement the behavior function
function OnLoop(model_fs:IRvFreeSpin3D):void {
var forwardVector:Vector3D = model_fs.RviVectorForward;
// move the sky according to the forward direction of the plane
Sky.x -= forwardVector.x * speed;
Sky.y -= forwardVector.y * speed;
if(Sky.x >= tileWidth || Sky.x <= -tileWidth)
Sky.x = 0;
if(Sky.y >= tileWidth || Sky.y <= -tileWidth)
Sky.y = 0;
}
The Adobe Flash CS3 Actions Layer
import FreeSpin3D.IRvFreeSpin3D;
// Add a function to the 3D model as a behavior - named OnLoop
plane_mc.my3DModel_fs.RviBehaviorFunction = OnLoop;
var speed:Number = 5;
var tileWidth:Number = 425;
function OnLoop(model_fs:IRvFreeSpin3D):void {
var forwardVector:Array = model_fs.RviVectorForward;
Sky.x -= forwardVector[0] * speed;
Sky.y -= forwardVector[1] * speed;
if(Sky.x >= tileWidth || Sky.x <= -tileWidth)
Sky.x = 0;
if(Sky.y >= tileWidth || Sky.y <= -tileWidth)
Sky.y = 0;
}

