OH! I see. I have to instantiate a variable and iterate off that. I knew it was something simple I was missing. Really loving how I can organize numerous assets with the library. great implementation
On May 24, 8:24 am, Ross Smith <[email protected]> wrote: > Brilliant feature, thanks for adding this. > > > > > > > > > > On Tue, May 24, 2011 at 4:02 AM, richardolsson <[email protected]> wrote: > > Hi Choons, > > > Are you familiar with iterators in general? This is a very simple (but > > powerful ;)) implementation of that pattern. This is how you use it if > > you want to loop through all assets that has been loaded: > > > var asset : IAsset; > > var it : AssetLibraryIterator = AssetLibrary.createIterator(); > > while (asset = it.next()) { > > trace(asset.name); > > } > > > You can also jump back and forth (or use a for loop if you prefer) > > using the numAssets property and setIndex() method, and retrieve the > > current asset using the currentAsset property: > > > var i : uint; > > for (i=0; i < it.numAsset; i++) { > > it.setIndex(i); > > trace(it.currentAsset.name); > > } > > > If you want to limit the iteration to just a particular type, or a > > particular namespace, you specify these as parameters in the > > createIterator call: > > > AssetLibrary.createIterator(AssetType.MESH); // Only meshes > > AssetLibrary.createIterator(null, "myns"); // All in NS "myns" > > AssetLibrary.createIterator(AssetType.MESH, "myns"); // Both > > > The third example above will only return meshes in namespace "myns", > > i.e. no materials, textures or anything else from that namespace, and > > no meshes from any other namespace. > > > If you want to filter using some custom method, use the third > > parameter to define a function callback which will be invoked with a > > single parameter (the asset) for every asset during the filter stage. > > That method must return a boolean indicating whether the particular > > asset should be included or not. > > > function includeIfCar(asset : IAsset) : Boolean > > { > > if (asset.name.indexOf('car')>=0) > > return true; > > else > > return false; > > } > > > AssetLibrary.createIterator(null,null, includeIfCar); > > > Regardless of how you invoke createIterator(), the returned object is > > always an iterator that you should use the way I described above. Hope > > this helps! > > > Cheers > > /R > > > On May 24, 6:13 am, Choons <[email protected]> wrote: > > > Hi folks- I'm working on my first multi- asset project using the > > > AssetLibrary. I named everything on the ASSET COMPLETE event and need > > > to loop through the library to initialize it all. It seems like > > > createIterator is the function for that but I can't get it to > > > recognize any of my input params. How do you use that beast? > > -- > Ross Smith > [email protected]
