AssetLibrary.load()

Software: Away3D 4.x

cervantez, Newbie
Posted: 28 August 2012 12:09 PM   Total Posts: 6

Scenario:
I load several assets via AssetLibrary.load() at the same time and I use the same method to listen to, say AssetEvent.MESH_COMPLETE events.

When loaded I want them to be stored in my AssetLibrary via addAsset, but I don´t know what I´ve loaded. I thought well I could use _namespace via event.asset.assetNamespace but thats not really what namespace is intended to be used for, right?

So what would be the proper way to do it?
Some code to get the idea…

var ldr:AssetLoaderToken=AssetLibrary.load(new URLRequest("mesh.3ds"),new AssetLoaderContext(),"bla",new Max3DSParser());
var 
ldr1:AssetLoaderToken=AssetLibrary.load(new URLRequest("mesh1.3ds"),new AssetLoaderContext(),"bla1",new Max3DSParser());
var 
ldr2:AssetLoaderToken=AssetLibrary.load(new URLRequest("mesh2.3ds"),new AssetLoaderContext(),"bla2",new Max3DSParser());

protected function 
test(event:AssetEvent):void
  {
switch(event.asset.assetNamespace)
  
{
     
case "bla":
     case 
"bla1":
  
}
   

Richard Olsson, Administrator
Posted: 28 August 2012 01:08 PM   Total Posts: 1192   [ # 1 ]

If you’re already using AssetLibrary to load files, they will be automatically added using the names that are defined in the files. You should definitely not be using addAsset() if you are already loading a file through AssetLibrary. At most you could change the names of the assets as they come in.

If the names from the actual files are useless (in which case you should probably take a look at your asset pipeline) there are basically two or three ways of giving new names to assets that are loaded in parallel.

One is to use the namespace property like you seem to be suggesting. You can do that, but like you’re saying it’s a waste of namespaces to have one for every model.

Or you can split up your handler methods so that each loading operation has it’s own listener callback.

Finally, as an alternative to the last approach, you can also build your own queuing/parallel loading system where each loading operation is a self-contained entity with it’s own methods to add assets to the library.

   

cervantez, Newbie
Posted: 28 August 2012 02:05 PM   Total Posts: 6   [ # 2 ]

Thought I´d use…

function resetAssetPath(name Stringns String=nulloverrideOriginal Boolean true) : void

... then. To get rid of the loading namespace and only keep the name like so:

event.asset.resetAssetPath(event.asset.assetNamespace); 

But when I do this AssetLibrary.getAsset(event.asset.name); returns null…

   

Richard Olsson, Administrator
Posted: 28 August 2012 02:08 PM   Total Posts: 1192   [ # 3 ]

Yes, because that will not update the AssetLibrary cache/look-up table. I would suggest that you use one of the other (more recommended) methods suggested in my previous post instead. Use namespace to namespace assets, not to tag them by URL, if you do not intend to keep that namespace.

   

cervantez, Newbie
Posted: 28 August 2012 02:17 PM   Total Posts: 6   [ # 4 ]

Aright. Will split up the handler method then Thanks for your help.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X