Create a new AssetManager. The 'scaleFactor' and 'useMipmaps' parameters define how enqueued bitmaps will be converted to textures.
Specifies whether a check should be made for the existence of a URL policy file before loading an object from a remote server. More information about this topic can be found in the 'flash.system.LoaderContext' documentation. @default false
Indicates if the underlying Stage3D textures should be created as the power-of-two based
Texture
class instead of the more memory efficient RectangleTexture
.
@default false
Indicates if a queue is currently being loaded.
Indicates if atlas XML data should be stored for access via the 'getXml' method. If true, you can access an XML under the same name as the atlas. If false, XMLs will be disposed when the atlas was created. @default false.
Indicates if bitmap font XML data should be stored for access via the 'getXml' method. If true, you can access an XML under the same name as the bitmap font. If false, XMLs will be disposed when the font was created. @default false.
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.
The queue contains one 'Object' for each enqueued asset. Each object has 'asset' and 'name' properties, pointing to the raw asset and its name, respectively.
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 that are created from Bitmaps or ATF files will have the scale factor assigned here. @default 1
Textures that are created from Bitmaps will be uploaded to the GPU with the
Context3DTextureFormat
assigned to this property. @default "bgra"
For bitmap textures, this flag indicates if mip maps should be generated when they are loaded; for ATF textures, it indicates if mip maps are valid and should be used. @default false
When activated, the class will trace information about added/enqueued assets.
Register a bitmap font under a certain name. It will be available right away. If the name was already taken, the existing font will be disposed and replaced by the new one.
Note that the font is not registered at the TextField class. This only happens when a bitmap font is loaded via the asset queue.
Register a byte array under a certain name. It will be available right away. If the name was already taken, the existing byte array will be cleared and replaced by the new one.
Registers an event listener at a certain object.
Register an arbitrary object under a certain name. It will be available right away. If the name was already taken, the existing object will be replaced by the new one.
Register a sound under a certain name. It will be available right away. If the name was already taken, the existing sound will be replaced by the new one.
Register a texture under a certain name. It will be available right away. If the name was already taken, the existing texture will be disposed and replaced by the new one.
Register a texture atlas under a certain name. It will be available right away. If the name was already taken, the existing atlas will be disposed and replaced by the new one.
Register an XML object under a certain name. It will be available right away. If the name was already taken, the existing XML will be disposed and replaced by the new one.
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 contained textures, XMLs and ByteArrays.
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 that contain texture atlases or bitmap fonts are processed directly: fonts are registered at the TextField class, atlas textures can be acquired with the "getTexture()" method. All other XMLs are available via "getXml()".
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.
The asset that will be enqueued; accepts the same objects as the 'enqueue' method.
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.
Custom options that will be used if 'asset' points to texture data.
the name with which the asset was registered.
Returns a bitmaps font with a certain name, or null if it's not found.
Returns all bitmap fonts 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. The method first looks through the directly added textures; if no texture with that name is found, it scans through all texture 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.
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 'onProgress' will be called with a 'ratio' between '0.0' and '1.0', with '1.0' meaning that it's complete.
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.
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.
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 (and you have enabled 'Starling.handleLostContext'), 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 timeframe 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 dispatch events of type "IO_ERROR", "SECURITY_ERROR" or "PARSE_ERROR". You can listen to those events and handle the errors manually (e.g., you could enqueue them once again and retry, or provide placeholder textures). Queue processing will continue even when those events are dispatched.
Using variable texture formats
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: