Subobject index detection by MouseEvent

Software: Away3D 4.x

GiGBiG, Member
Posted: 29 March 2013 03:43 PM   Total Posts: 57

Hi,
I need to listen for clicks on a mesh formed by more elements: I need to know the index of the clicked subobject.

In another project I have used the approach of adding a listener to each subobject, but in this new project I have a lot more subobjects: I’d prefer to use a single MouseEvent listener for the main mesh containing the subobjects, and act when I know the index of the clicked one.

I have tried to put the listener, but the target/currentTarget I receive in the event output is the whole mesh.

Thanks

   

aeki, Member
Posted: 30 March 2013 10:35 PM   Total Posts: 73   [ # 1 ]

When loading your model, listen to LoaderEvent.MESH_COMPLETE, then for each mesh sub object of your model set mesh.mouseEnabled = true

Then set a listener to MouseEvent, and in the handler you should access the targeted sub object with Mesh(event.target).

   

GiGBiG, Member
Posted: 02 April 2013 08:24 AM   Total Posts: 57   [ # 2 ]

I am instantiating an AS3 model (MainModel, a mesh exported as AS3 Class with Prefab3D).

I have set all mouseEnabled

for (0mainMesh.meshes.lengthi++) {
 mainMesh
.meshes[i].mouseEnabled true;
}
mainMesh
.mouseChildren true// to be sure

mainMesh.addEventListener(MouseEvent3D.MOUSE_UPonMouseUp);

function 
onMouseUp(eMouseEvent3D): void {
 trace
(e.currentTarget);
 
trace("id = " mainMesh.meshes.indexOf(e.currentTarget));

traces

[object MainModel]
id 
= -

as before, as if I was clicking on the main mesh, and not the subobject.
What am I doing wrong?

P.S.: with e.target the result is the same.

   

aeki, Member
Posted: 02 April 2013 08:45 AM   Total Posts: 73   [ # 3 ]

You should try trace(e.object) instead of trace(e.currentTarget);

   

GiGBiG, Member
Posted: 02 April 2013 09:57 AM   Total Posts: 57   [ # 4 ]

Great! Now it works!
Woah! And mouseEnabled is not necessary anymore!
Thank you.
But, why “object” instead of “target”?

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X