How to reference the Loader3D that triggered the LoaderEvent ?

Software: Away3D 4.x

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2011 02:24 AM   Total Posts: 344

Basically, Im trying to reference the Loader3D which triggers a loaderEvent from within the function which is called.

This is where I’m at: (the bit between stars is what I’m trying to do)

private function addStaffMember():void
  
  {
  
   
for (var i:uint 0numStaffi++)
   
   
   
{
   Loader3D
.enableParser(OBJParser);
   var 
staffLoader:Loader3D = new Loader3D();
   
staffLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETEmemberLoaded);
   
staffLoader.load(new URLRequest("models/staff/" +staffArray[i].obj +staffArray[i].obj +".obj" ));
   
_view.scene.addChild(staffLoader); 
   
}
   
  }
  
  
private function memberLoaded (eventLoaderEvent) :void
  
  {
   
  
***** var staffLoader event.Loader3D;*****




   var 
staffMesh Mesh;
   for (var 
int 0staffLoader.numChildren; ++i
   
{
    staffMesh 
Mesh(staffLoader.getChildAt(i));
    
staffMesh.geometry.scale(100);
   
    var 
staffMaterials DefaultMaterialBase = new ColorMaterial(0xfff6d9);
    
staffMaterials.ambientColor 0x303040;
    
staffMaterials.lights [_light];
    
    
staffMesh.material staffMaterials;
    
staffMesh.addEventListener(MouseEvent3D.MOUSE_DOWNstaffClick);
    
staffMesh.mouseEnabled true;
   
}
   
   
  } 

Basically, I’m trying to do the equivalent of

private function staffClick (eMouseEvent3D):void
  {
   
//this references the 3d object that sent the trigger
   
currentTarget e.object;
   
  

but for a Loader event.

Any ideas?

   

Richard Olsson, Administrator
Posted: 26 July 2011 07:50 AM   Total Posts: 1192   [ # 1 ]

As is always the case in Flash programming (regardless whether you’re using Away3D or not) Event.currentTarget references the object on which you added your listener, in this case the Loader3D instance from which the event is being dispatched.

trace(event.currentTarget) should trace Loader3D.

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2011 01:43 PM   Total Posts: 344   [ # 2 ]
Richard Olsson - 26 July 2011 07:50 AM

As is always the case in Flash programming (regardless whether you’re using Away3D or not) Event.currentTarget references the object on which you added your listener, in this case the Loader3D instance from which the event is being dispatched.

trace(event.currentTarget) should trace Loader3D.

Aha… Good to know. I started out learning AS3 from modiftying papervision examples, and so I’m finding that although I can do some pretty advanced things 3D wise, the basics leave me scratching my head…

I sort of worked a kludge version last night, like this:

private function addStaffMember():void
  
  {
   
var CurrentStaffIndex;
   
trace ("i is " );
   
Loader3D.enableParser(OBJParser);
   var 
staffLoader:Loader3D = new Loader3D();
   
CurrentStaffLoader staffLoader;
   
staffLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETEmemberLoaded);
   
staffLoader.load(new URLRequest("models/staff/" +staffArray[i].obj+"/" +staffArray[i].obj +".obj" ));
   
_view.scene.addChild(staffLoader); 
  
}
  
  
private function memberLoaded (eLoaderEvent) :void
  
  {
   
var staffLoader CurrentStaffLoader;
   var 
staffMesh Mesh;
   for (var 
int 0staffLoader.numChildren; ++i
   
{
    staffMesh 
Mesh(staffLoader.getChildAt(i));
    
staffMesh.geometry.scale(100);
    
//mesh.y = -700
    //_loader.x = 300
    //_loader.z = -500
    
staffMesh.extra { staffIndex:new Number };
    
staffMesh.extra.staffIndex CurrentStaffIndex;
    
    var 
staffMaterials DefaultMaterialBase = new ColorMaterial(0x00ff00);
    
staffMaterials.ambientColor 0x303040;
    
staffMaterials.lights [_light];
    
staffMesh.material staffMaterials;
    
staffMesh.castsShadows true;
    
staffMesh.addEventListener(MouseEvent3D.MOUSE_DOWNstaffClick);
    
staffMesh.mouseEnabled true;
   
}
   
   
if (CurrentStaffIndex < (numStaff 1))
    
{
     CurrentStaffIndex
++
     
addStaffMember();
    
}
   
  } 

So it basically advances through each .obj only after the memberLoaded function has finished…


I’ll probably go back and do it the cleaner way though, now I know how it should be done..

   

Mr Margaret Scratcher, Sr. Member
Posted: 26 July 2011 02:16 PM   Total Posts: 344   [ # 3 ]

Ha ! did it the proper way and it broke something that my kludge did right…

Captain Wrong-Way wins again!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X