Access AWD objects using AWDParser2…how to?

Software: Away3D 4.x

Avatar
miyijura, Newbie
Posted: 12 May 2014 06:19 PM   Total Posts: 6

Hello, here´s an overview of my problem:

1- I am loading an AWD file made with AwayBuilder. This test file is composed of cubeA, cubeB (both are cubes smile ) and terrain.
2- In my init() i have:

AssetLibrary.enableParser(AWD2Parser);
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
//kickoff asset loading
var loader:Loader3D = new Loader3D();
loader.load(new URLRequest("../embeds/two_cubes.awd"));
   
_view.scene.addChild(loader); 

3- I want to click the cubes and trace a message, so later i can figure out how to make this scene more interactive and with more complex features.

What is the best way to achieve this?

I tried this:

private function onAssetComplete(event:AssetEvent):void
  {
   trace
(event.asset.name);
   
   if (
meshContainer ObjectContainer3D(AssetLibrary.getAsset("cubeA"))) {
    
//cubeA.addEventListener(MouseEvent3D.MOUSE_DOWN, clickAction);
    
trace("the element:" meshContainer.name " exists in the scene" );
   
}
   
  } 

The trace output shows the message confirming that those elements exists, but i can´t figure out how to add mouse events to them.


Any advice is welcome.
Thanks guys!

   

Avatar
miyijura, Newbie
Posted: 12 May 2014 06:48 PM   Total Posts: 6   [ # 1 ]

I make it work with this..please advice me if this is the best method:

//this go on the private vars zone
private var meshContainer:ObjectContainer3D;
private var 
cubeA:Mesh;

private function 
onAssetComplete(event:AssetEvent):void
  {
   trace
(event.asset.name);
   
   if (
meshContainer ObjectContainer3D(AssetLibrary.getAsset("cubeB"))) {
    meshContainer
.mouseEnabled true;
    
meshContainer.addEventListener(MouseEvent3D.MOUSE_DOWNclickAction);
    
//trace("the element:" + meshContainer.name + " exists in the scene" );
   
}
   
  }

private function clickAction(e:MouseEvent3D):void 
  {
   trace
("hello world");
  

This is the best/correct approach?
Regards!

   

rdoi, Member
Posted: 22 August 2014 04:55 PM   Total Posts: 86   [ # 2 ]

Hi there, you’d probably already got over this, but just to note:

You don’t need to query the AssetLibrary, you can use the AssetEvent.asset of ASSET_COMPLETE event, and all its properties.

Just detect the correct object by using event.asset.assetType and event.asset.name and assign it to some variable for public access after RESOURCE_COMPLETE event.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X