Adding MOUSE_OVER event to ObjectContainer3D?

Software: Away3D 4.x

Avatar
owntheweb, Jr. Member
Posted: 15 February 2013 08:02 PM   Total Posts: 32

Hey,
I created a “Tile()” containing multiple messes in Prefab3D, exported for Away3D. It extends ASBase() which extends ObjectContainer3D() in a predictable Prefab3D manner. I also exported a “PrefabProject.as” from which I’m expanding upon below.

How do I trigger a mouse over event for my new Tile() object? I’ve tried the following based on this tutorial for meshes (no errors but no results either, perhaps because it’s not a mesh!):
http://away3d.com/tutorials/Introduction_to_Mouse_Picking

...
  private function 
initContent():void
  {
   _prefabOutput 
= new Tile();
   
_view.scene.addChild(_prefabOutput);

   
//!!!new!!!
   
_prefabOutput.mouseEnabled true
   
_prefabOutput.addEventListenerMouseEvent3D.MOUSE_OVERonTileMouseOver );

   
_camera.lookAt(_prefabOutput.position);
   
  
}
  
  
//new function
  
private function onTileMouseOverevent:MouseEvent3D ):void {
   trace
('hi'); //sadly, no trace "hi"
   
event.target.onMouseOver(); //no trace "hi", so no do cool new things here
  
}
... 

Looking at the documentation, I see that an ObjectContainer3D() does have a “mouseOver3d” event, but getting it to click in my brain isn’t happening at the moment.
http://away3d.com/livedocs/away3d/4.0/away3d/containers/ObjectContainer3D.html#event:mouseOver3d

Any thoughts on how to proceed? I truly appreciate the assistance in advance!

Best regards,

Chris

   

Avatar
owntheweb, Jr. Member
Posted: 15 February 2013 09:11 PM   Total Posts: 32   [ # 1 ]

Ok, so far I’ve been able to get this partially resolved. I can target all of the child meshes of the Tile() object and get the mouse over method called (YAY!).

private function initContent():void
  {
   _prefabOutput 
= new Tile();
   
_view.scene.addChild(_prefabOutput);
   
   
//new
   
for(var i:Number=0;i<_prefabOutput.meshes.length;++i){
    _prefabOutput
.meshes[i].mouseEnabled true;
    
_prefabOutput.meshes[i].addEventListenerMouseEvent3D.MOUSE_OVERonTileMouseOver );
   
}
   
   _camera
.lookAt(_prefabOutput.position);
  
}
  
  
  
private function onTileMouseOverevent:MouseEvent3D ):void {
   trace
('hi'); //YAY IT WORKS!
   
   //uh oh, need to get Tile()'s methods, not child mesh's non-existing method
   
event.target.onMouseOver();
  

But now I’m having scope issues, needing to call the parent Tile() method onMouseOver, not the event.target non-existing onMouseOver event. I’ll keep digging. Let me know if I should skip all this and do something simpler.

Thanks…

 

   

Avatar
owntheweb, Jr. Member
Posted: 15 February 2013 09:18 PM   Total Posts: 32   [ # 2 ]

Alright this works fully:

private function initContent():void
  {
   _prefabOutput 
= new Tile();
   
_view.scene.addChild(_prefabOutput);
   
   for(var 
i:Number=0;i<_prefabOutput.meshes.length;++i){
    _prefabOutput
.meshes[i].mouseEnabled true;
    
_prefabOutput.meshes[i].addEventListenerMouseEvent3D.MOUSE_OVERonTileMouseOver );
   
}
   
   _camera
.lookAt(_prefabOutput.position);
  
}
  
  
  
private function onTileMouseOverevent:MouseEvent3D ):void {
   
//ok this works...
   
event.target.parent.parent.parent.parent.onMouseOver();
  

BUT: is there a way to add mouse over events only to the parent Tile() object and not its child meshes? “event.target.parent.parent.parent.parent.onMouseOver();” looks a bit messy to me, and one event listener seems better than the 4 I’m currently using. wink

Thanks again,

EDIT: I had a misunderstanding of what “submeshes” were. I reconstructed, imported and am now reconfiguring a game piece so it now is ONE mesh with 4 submeshes. That makes my mouse interaction easier with less mouse event tracking.

I’m still curious about ObjectContainer3D() mouse interaction, but am doing well enough to proceed now. Thanks for taking a look. :D

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X