Create a new instance with the given scale factor.
The DataLoader is used to load any data from files or URLs. If you need to customize its behavior (e.g. to add a caching mechanism), assign your custom instance here.
The maximum number of parallel connections that are spawned when loading the queue. More connections can reduce loading times, but require more memory. @default 3.
Returns the number of raw assets that have been enqueued, but not yet loaded.
Indicates if bitmap fonts should be registered with their "face" attribute from the font XML file. Per default, they are registered with the name of the texture file. @default false
Textures will be created with the options set up in this object at the time of enqueuing.
When activated, the class will trace information about added/enqueued assets. @default true
Add an asset with a certain name and type.
Beware: if the slot (name + type) was already taken, the existing object will be disposed and replaced by the new one.
@param name The name with which the asset can be retrieved later. Must be unique within this asset type. @param asset The actual asset to add (e.g. a texture, a sound, etc). @param type The type of the asset. If omitted, the type will be determined automatically (which works for all standard types defined within the 'AssetType' class).
Registers an event listener at a certain object.
Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.
Dispatches an event with the given parameters to all objects that have registered listeners for the given type. The method uses an internal pool of event objects to avoid allocations.
Disposes all assets and purges the queue.
Beware that all references to the assets will remain intact, even though the assets are no longer valid. Call 'purge' if you want to remove all resources and reuse the AssetManager later.
Enqueues one or more raw assets; they will only be available after successfully executing the "loadQueue" method. This method accepts a variety of different objects:
png, jpg, gif, atf, mp3, xml, fnt, json, binary
.static
embedded assets.Suitable object names are extracted automatically: A file named "image.png" will be accessible under the name "image". When enqueuing embedded assets via a class, the variable name of the embedded object will be used as its name. An exception are texture atlases: they will have the same name as the actual texture they are referencing.
XMLs are made available via "getXml()"; this includes XMLs containing texture atlases or bitmap fonts, which are processed along the way. Bitmap fonts are also registered at the TextField class.
If you pass in JSON data, it will be parsed into an object and will be available via "getObject()".
Enqueues a single asset with a custom name that can be used to access it later. If the asset is a texture, you can also add custom texture options.
@param asset The asset that will be enqueued; accepts the same objects as the 'enqueue' method. @param name The name under which the asset will be found later. If you pass null or omit the parameter, it's attempted to generate a name automatically. @param options Custom options that will be used if 'asset' points to texture data. @return the name with which the asset was registered.
Retrieves an asset of the given type, with the given name. If 'recursive' is true, the method will traverse included texture atlases and asset managers.
Typically, you will use one of the type-safe convenience methods instead, like 'getTexture', 'getSound', etc.
Returns an asset manager with a certain name, or null if it's not found.
Returns all asset manager names that start with a certain string, sorted alphabetically.
If you pass an out
-vector, the names will be added to that vector.
Retrieves an alphabetically sorted list of all assets that have the given type and start with the given prefix. If 'recursive' is true, the method will traverse included texture atlases and asset managers.
Returns a bitmap font with a certain name, or null if it's not found.
Returns all bitmap font names that start with a certain string, sorted alphabetically.
If you pass an out
-vector, the names will be added to that vector.
Returns a byte array with a certain name, or null if it's not found.
Returns all byte array names that start with a certain string, sorted alphabetically.
If you pass an out
-vector, the names will be added to that vector.
Returns an object with a certain name, or null if it's not found. Enqueued JSON data is parsed and can be accessed with this method.
Returns all object names that start with a certain string, sorted alphabetically.
If you pass an out
-vector, the names will be added to that vector.
Returns a sound with a certain name, or null if it's not found.
Returns all sound names that start with a certain string, sorted alphabetically.
If you pass an out
-vector, the names will be added to that vector.
Returns a texture with a certain name. Includes textures stored inside atlases.
Returns a texture atlas with a certain name, or null if it's not found.
Returns all texture atlas names that start with a certain string, sorted alphabetically.
If you pass an out
-vector, the names will be added to that vector.
Returns all texture names that start with a certain string, sorted alphabetically. Includes textures stored inside atlases.
Returns an XML with a certain name, or null if it's not found.
Returns all XML names that start with a certain string, sorted alphabetically.
If you pass an out
-vector, the names will be added to that vector.
If called with one argument, figures out if there are any listeners registered for the given event type. If called with two arguments, also determines if a specific listener is registered.
Loads all enqueued assets asynchronously. The 'onComplete' callback will be executed once all assets have been loaded - even when there have been errors, which are forwarded to the optional 'onError' callback. The 'onProgress' will be called with a 'ratio' between '0.0' and '1.0' and is also optional.
When you call this method, the manager will save a reference to "Starling.current"; all textures that are loaded will be accessible only from within this instance. Thus, if you are working with more than one Starling instance, be sure to call "makeCurrent()" on the appropriate instance before processing the queue.
@param onComplete function(manager:AssetManager):void;
- parameter is optional!
@param onError function(error:string):void;
@param onProgress function(ratio:Number):void;
Generates a new SoundChannel object to play back the sound. This method returns a SoundChannel object, which you can access to stop the sound and to control volume.
Removes assets of all types (disposing them along the way), empties the queue and aborts any pending load operations.
Empties the queue and aborts any pending load operations.
Registers a custom AssetFactory. If you use any priority > 0, the factory will be called before the default factories. The final factory to be invoked is the 'ByteArrayFactory', which is using a priority of '-100'.
Removes the asset with the given name and type, and will optionally dispose it.
Removes a certain asset manager and optionally disposes it right away.
Removes a certain bitmap font, optionally disposing it.
Removes a certain byte array, optionally disposing its memory right away.
Removes an event listener from the object.
Removes all event listeners with a certain type, or all of them if type is null. Be careful when removing all event listeners: you never know who else was listening.
Removes a certain object.
Removes a certain sound.
Removes a certain texture, optionally disposing it.
Removes a certain texture atlas, optionally disposing it.
Removes a certain Xml object, optionally disposing it.
Generated using TypeDoc
The AssetManager handles loading and accessing a variety of asset types. You can add assets directly (via the 'add...' methods) or asynchronously via a queue. This allows you to deal with assets in a unified way, no matter if they are loaded from a file, directory, URL, or from an embedded object.
The class can deal with the following media types:
For more information on how to add assets from different sources, read the documentation of the "enqueue()" method.
Context Loss
When the stage3D context is lost, the AssetManager will automatically restore all loaded textures. To save memory, it will get them from their original sources. Since this is done asynchronously, your images might not reappear all at once, but during a time frame of several seconds. If you want, you can pause your game during that time; the AssetManager dispatches an "Event.TEXTURES_RESTORED" event when all textures have been restored.
Error Handling
Loading of some assets may fail while the queue is being processed. In that case, the AssetManager will call the 'onError' callback that you can optional provide to the 'loadQueue' method. Queue processing will continue after an error, so it's always guaranteed that the 'onComplete' callback is executed, too.
Texture Properties
When you enqueue a texture, its properties for "format", "scale", "mipMapping", and "repeat" will reflect the settings of the AssetManager at the time they were enqueued. This means that you can enqueue a bunch of textures, then change the settings and enqueue some more. Like this:
Nesting
When you enqueue one or more AssetManagers to another one, the "loadQueue" method will oad the Assets of the "child" AssetManager, as well. Later, when accessing assets, the "parent" AssetManager will return the "child" assets as well - just like it returns, say, the SubTextures from a contained TextureAtlas.
The main advantage of grouping your assets like this is something else, though: it allows to remove (and dispose) a complete group of assets in one step. The example below loads the assets from two directories. When the contents of one of them are no longer needed, all its assets are removed together.
Customization
You can customize how assets are created by extending the 'AssetFactory' class and registering an instance of your new class at the AssetManager via 'registerFactory'. Factories are probed by priority; any factory with a priority > 0 will be executed before the built-in factories.
An asset type is identified by a unique String. You can add your own asset types by creating a custom 'AssetFactory' and having it add the asset with custom string identifier.
By overriding the methods 'getNameFromUrl', 'getExtensionFromUrl', 'disposeAsset', and 'log', you can customize how assets are named and disposed, and you can forward any logging to an external logger. To customize the way data is loaded from URLs or files, you can assign a custom 'DataLoader' instance to the AssetManager.
@see starling.assets.AssetFactory @see starling.assets.AssetType @see starling.assets.DataLoader