Adobe Solution Partner
FreeSpin3D - 3D for Adobe Flash Learn More Free Trial Buy FreeSpin3D

Code Samples

Duplicate a 3D Model Instance

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

Click on the example, use the keyboard arrows to rotate the donut and click the button to duplicate it.
Download the Source Files for Adobe Flash CS4
Download the Source Files for Adobe Flash CS3

About the Example

In this example I used the FreeSpin3D Action Script API to duplicate a 3D model instance that is on the stage. When duplicating, a new instance of the 3D model is created with the same properties and settings as the duplicated 3D model instance.

The FLA

In the FLA I imported a 3D model of a donut using the FreeSpin3D Import Engine. I created a background and dragged the FreeSpin3D component to the stage, then assigned it the donut 3D model. I gave the donut  the instance name my3DModel_fs so I can relate to it in the Action Script API.  I turned the keyboard control to true (in the FreeSpin3D Control panel).

I added a button on the stage, so when clicked, it will duplicate the donut and create a new instance of it. For the duplicated instance of the donut I add an Auto Rotation when created (using the FreeSpin3D Action Script API).

Adobe Flash CS4The Adobe Flash CS4 Actions Layer (If using Adobe Flash CS3, see code in box below)

import FreeSpin3D.CRvFreeSpin3D;
import FreeSpin3D.IRvFreeSpin3D;

// Add a Mouse Click event listener to the Clone button
btnDuplicate.addEventListener(MouseEvent.CLICK, OnBtnClick);

function OnBtnClick(evt:MouseEvent):void
{
// clone the original donut 3D model instance
var duplicatedModel:CRvFreeSpin3D = my3DModel_fs.RviClone() as CRvFreeSpin3D;

// add the cloned donut to the stage
addChild(duplicatedModel);

// set the position of the cloned donut to the left of the original one
duplicatedModel.x = my3DModel_fs.x + my3DModel_fs.width - 25;
duplicatedModel.y = my3DModel_fs.y;

// set auto rotation to the cloned donut
duplicatedModel.RviAutoX = 1;
duplicatedModel.RviAutoY = 1;
duplicatedModel.RviAutoRender = true;

// disable the Clone button
btnDuplicate.enabled = false;
btnDuplicate.visible = false;
btbg.visible = false;
}

Adobe Flash CS4The Adobe Flash CS3 Actions Layer

mport FreeSpin3D.CRvFreeSpin3D;

// Add a mouse listener to the button used to dupliace the donut
btnDuplicate.addEventListener(MouseEvent.CLICK, OnBtnClick);

function OnBtnClick(evt:MouseEvent):void
{
// Duplicate the donut 3D model instance and create a new one
var duplicatedModel:CRvFreeSpin3D = my3DModel_fs.RviDuplicate() as CRvFreeSpin3D;

// Add the duplicated donut instance to the stage
addChild(duplicatedModel);

// Position the new donut to the left of the original one
duplicatedModel.x = my3DModel_fs.x + my3DModel_fs.width - 25;
duplicatedModel.y = my3DModel_fs.y;

// Add auto rotation to the new donut instance
duplicatedModel.RviAutoX = 1;
duplicatedModel.RviAutoY = 1;
duplicatedModel.RviSetRenderingLoop(true);

// Disable the button
btnDuplicate.enabled = false;
btnDuplicate.visible = false;
btbg.visible = false;
}