How do you select an exported as3 Prefab2 object with the mouse?

Software: Away3D 4.x

Bill7745, Newbie
Posted: 20 December 2015 01:21 AM   Total Posts: 22

Hi I’m trying to select an object with the mouse that I exported as an AS3 class from Prefab2. It’s a soldier that I’m trying to select:

_soldier = new Soldier();
  _soldier.scale(.10);
  _soldier.x = 0;
  _soldier.y = 25;
  _soldier.z = -100;
 
  _soldier.mouseEnabled = true;
  _soldier.addEventListener(MouseEvent3D.MOUSE_DOWN, _soldierOnMouseDown);
  scene.addChild(_soldier);

but it doesn’t work. Any idea how I could select it with the mouse so I can move it around.

   

Avatar
Fabrice Closier, Administrator
Posted: 20 December 2015 12:28 PM   Total Posts: 1265   [ # 1 ]

If you look at the Soldier class, you see its extending ObjectContainer3D.
However, your soldier (assuming with such name that the mesh doesn’t represent a coffee machine), is a child of this container.

So in order to set the listener, you actually need to access the mesh.
The exported class extends ASbase, which holds containers, meshes, materials arrays.
So if you know that the export holds only one mesh (the soldier)
you need to do:
var container:Soldier = new Soldier();
var soldier:Mesh = container.meshes[0];
scene.addChild(soldier);

The confusion here comes from the name you gave to the export.
Where “army”, “legion” would better fit if the meshes in classes are soldiers.

As a side note, you should look at examples to define the hittest methods of the view and on mouse3Devents.

I order to “move it around”, take a look at the Drag3D class.

Shameless promo: Prefab 3.x will be available in a not so far future. With tons of new features added…

   

Bill7745, Newbie
Posted: 20 December 2015 09:09 PM   Total Posts: 22   [ # 2 ]

thanks for answering my question. It looks like the soldier is made up of several meshes. Is there a way to add the MouseEvent3D event listener to all the meshes that make up the soldier at once?

   

Bill7745, Newbie
Posted: 20 December 2015 09:26 PM   Total Posts: 22   [ # 3 ]

I read in this post that I could reconstruct the soldier so it is one mesh so I’ll try that:

http://away3d.com/forum/viewthread/3999/

   

Sporph, Newbie
Posted: 18 April 2016 08:04 AM   Total Posts: 1   [ # 4 ]
Bill7745 - 20 December 2015 09:09 PM

thanks for informing everyone about Hydrow rower and answering my question. It looks like the soldier is made up of several meshes. Is there a way to add the MouseEvent3D event listener to all the meshes that make up the soldier at once?

I think there might be a way to group them is that correct that that we can select them all as a container? Do you know how to do this now?

   

Bill7745, Newbie
Posted: 18 April 2016 06:09 PM   Total Posts: 22   [ # 5 ]

you have to make them all one mesh in your 3d program

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X