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

Code Samples

Load Texture

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 cellular phone, click on the button to change the texture.
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 load a dynamic texture in runtime. Note: Changing textures are on file basis, meaning that you can load a new texture file instead of an existing one. 3D models may have one or more texture files, each has its own index. Before changing a texture file you need to know the index of the texture file you wish to change (indexes start at 0).

The FLA

For this example I used a 3D model of a cellular phone that has two texture files, one for the screen and one for the rest. In the FLA I imported the cellular phone 3D model using the FreeSpin3D Import Engine, created a background and an instance of the cellular 3D model on the stage. Using the FreeSpin3D Control Panel I add a keyboard control to the cellular phone, so it can be rotated using the keyboard arrows. I converted the cellular phone instance to a symbol, and added to it Glow and Shadow filters (using the Adobe Flash filters).

Using the FreeSpin3D Action Script API I dynamically load a texture that replaces the screen texture file (which has the index number 1).

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

// save the original texture of the 3D model (used later)
var originalTextureObj:DisplayObject = new CellPhone_T1();

// add a mouse click listener to the load texture button
btnChangeTexture.addEventListener(MouseEvent.CLICK, OnBtnClick);

function OnBtnClick(evt:MouseEvent):void
{
if(btnChangeTexture.label == "Load Texture")
{

// load an external texture file
Mc.my3DModel_fs.RviLoadTexture
("http://www.freespin3d.com/images/CellPhone_New.jpg", 1);

// change the text of the button
btnChangeTexture.label = "Revert";
}
else
{
// replace the loaded texture with the current one
Mc.my3DModel_fs.RviSetTextureFromDisplayObject(originalTextureObj, 1);

// change the text of the button
btnChangeTexture.label = "Load Texture";
}
}

Adobe Flash CS4The Adobe Flash CS3 Actions Layer

// Save the original texture object of the 3D model, for later use
var originalTextureObj:DisplayObject = new CellPhone_T1();

// Add a mouse listener to the button - used to dynamically change the texture
btnChangeTexture.addEventListener(MouseEvent.CLICK, OnBtnClick);

 function OnBtnClick(evt:MouseEvent):void
{
if(btnChangeTexture.label == "Load Texture")
{
// Load the external texture file
Mc.my3DModel_fs.RviLoadTexture("CellPhone_New.jpg", 1);

// Change the text on the button
btnChangeTexture.label = "Revert";
}
else
{
// Replace the external loaded texture with the original one
Mc.my3DModel_fs.RviSetTextureFromDisplayObject(originalTextureObj, 1);

// Change the text on the button
btnChangeTexture.label = "Load Texture";
}
}