Just declare the materials in class. Either give them an id or compare
them in your mouseEvent handler. Or compare with Cubedata id.
No need to extend anything here.
Sent from an iPhone without Flash
On Jun 13, 2010, at 3:28, Darcey Lloyd <[email protected]> wrote:
Hi,
Was just trying to work out how to work out which side of a cube is
being clicked.
If I was to use a bitmap material for each side, how would I check
for which side is clicked?
Here is my code:
private function createCube():void
{
var mat1:WireColorMaterial = new WireColorMaterial(0xFFCC00);
var mat2:ColorMaterial = new ColorMaterial(0xFF00FF);
var mat3:BitmapMaterial = new BitmapMaterial( Cast.bitmap(new hal
()) );
var mat4:BitmapMaterial = new BitmapMaterial( Cast.bitmap(new hal
()) );
var mat5:BitmapMaterial = new BitmapMaterial( Cast.bitmap(new hal
()) );
var mat6:BitmapMaterial = new BitmapMaterial( Cast.bitmap(new hal
()) );
cube = new Cube();
cube.cubeMaterials.front = mat1;
cube.cubeMaterials.back = mat2;
cube.cubeMaterials.left = mat3;
cube.cubeMaterials.right = mat4;
cube.cubeMaterials.top = mat5;
cube.cubeMaterials.bottom = mat6;
view.scene.addChild(cube);
cube.addOnMouseDown(click);
}
private function click(e:MouseEvent3D):void
{
// cube = e.target
// material = e.material
trace("e.material = " + e.material);
trace("f.material = " + f.material);
//trace("cube.faceVOs = " + cube.faceVOs);
var f:Face = cube.faces[0]; // which face[index] is the side we
want to test? will this change on segments value?
// This results in error
if (f.material == mat3){
trace("mat3");
} else {
trace("not mat3");
}
}
The solution I have modifies the Away3D classes themselves, which I
guess is not a good idea.
FILE: away3d.materials.Material.as
ADDED:
/** @private */
arcane var _materialName:String;
public function get matNames():String { return _materialName; }
public function set matNames(s:String):void { _materialName =
s; }
FILE: away3d.events.MouseEvent3D.as
ADDED:
public var materialName:String;
The above modifications allow me to do the following:
private function createCube():void
{
// Create material and plane
var mat1:WireColorMaterial = new
WireColorMaterial(0xFFCC00);
mat1.matName = "mat1";
var mat2:ColorMaterial = new ColorMaterial(0xFF00FF);
mat2.matName = "mat2";
var mat3:BitmapMaterial = new BitmapMaterial( Cast.bitmap(new hal
()) );
mat3.matName = "hal 2000";
cube = new Cube();
cube.cubeMaterials.front = mat1;
cube.cubeMaterials.back = mat2;
cube.cubeMaterials.left = mat3;
view.scene.addChild(cube);
cube.addOnMouseDown(click);
// Init listeners
initListeners();
}
private function click(e:MouseEvent3D):void
{
// cube = e.target
// material = e.material
trace("e.target = " + e.target);
trace("e.material = " + e.material);
trace("e.material.matName = " + e.material.matName); // Gives me
mat1,mat2,hal 2000, null for the rest
}
Maybe a modification to material.as and MouseEvent3D.as for the svn?
or is there a way to do this that I am missing?
Thanks
Darcey