Hi Joseph,

you get an errror because Object3D does not have any material property.
To swap materials on importedobjects you have to parse through all its faces
and set the material of the faces to the one you like to have.

Here is a litte snippet for you:

for ( var i : Number = 0; i < object.children.length; i++ ) {
        for ( var j : Number = 0; j < object.children[i].faces.length; j++ ) {
                object.children[i].faces[j].material = new 
ShadingColorMaterial( c );
        }
}

In this case "object" will be your Object3D instance.

Hope this works. If not, try ObjectContainer3D instead of Object3D.


Roland





Am 27.04.2009 um 09:49 schrieb Joseph:


Hello,
Been looking at source code for (Basic09_BitmapMaterialExplorer.as).
Want to swap textures back and forth on an .obj ... not quite working,
though ...

Flex framework brought into project library ... CS4, away3d 3.3.3 ...

Import relavent away3d classes:
import away3d.core.utils.Cast;
import away3d.materials.BitmapMaterial;

I embed a couple of textures:
[Embed(source="assetts/teapot_1.jpg")]
public var texture1:Class;
[Embed(source="assetts/teapot_2.jpg")]
public var texture2:Class;

Declare material variables:
private var material1:BitmapMaterial;
private var material2:BitmapMaterial;

Load in .obj:
var obj1:Object3DLoader = Obj.load("assetts/teapot_1.obj",
{material:texture1});

On success grab handle:
obj1object3d = e.loader.handle;

Create new materials:
material1 = new BitmapMaterial( Cast.bitmap( new this[texture1]() as
Bitmap ));
material2 = new BitmapMaterial( Cast.bitmap( new this[texture2]() as
Bitmap ));

On button press simply toggle materials with these calls:
obj1object3d.material = material1;
or
obj1object3d.material = material2;

But get error for the toggle material calls ...
1119: Access of possibly undefined property material through a
reference with static type away3d.core.base:Object3D.

Obviously for a primitive sphere.material works but for Object3D I
have to get it another way ... how would I do that?

BTW, all these things I'm learning I'm compiling into a "Common Noob
Mistakes" to help others as low level as I ...

Reply via email to