Packagestarling.assets
Classpublic class AssetFactory
InheritanceAssetFactory Inheritance Object
Subclasses AtfTextureFactory, BitmapTextureFactory, ByteArrayFactory, JsonFactory, SoundFactory, XmlFactory

An AssetFactory is responsible for creating a concrete instance of an asset.

The AssetManager contains a list of AssetFactories, registered via 'registerFactory'. When the asset queue is processed, each factory (sorted by priority) will be asked if it can handle a certain AssetReference (via the 'canHandle') method. If it can, the 'create' method will be called, which is responsible for creating at least one asset.

By extending 'AssetFactory' and registering your class at the AssetManager, you can customize how assets are being created and even add new types of assets.



Public Properties
 PropertyDefined By
  priority : int
AssetFactory
Public Methods
 MethodDefined By
  
Creates a new instance.
AssetFactory
  
addExtensions(... args):void
Add one or more file extensions (without leading dot) that identify the supported data types.
AssetFactory
  
addMimeTypes(... args):void
Add one or more mime types that identify the supported data types.
AssetFactory
  
canHandle(reference:AssetReference):Boolean
Returns 'true' if this factory can handle the given reference.
AssetFactory
  
create(reference:AssetReference, helper:AssetFactoryHelper, onComplete:Function, onError:Function):void
This method will only be called if 'canHandle' returned 'true' for the given reference.
AssetFactory
  
getExtensions(out:Vector.<String> = null):Vector.<String>
Returns the file extensions this factory supports.
AssetFactory
  
getMimeTypes(out:Vector.<String> = null):Vector.<String>
Returns the mime types this factory supports.
AssetFactory
Property Detail
priorityproperty
priority:int


Implementation
    public function get priority():int
    public function set priority(value:int):void
Constructor Detail
AssetFactory()Constructor
public function AssetFactory()

Creates a new instance.

Method Detail
addExtensions()method
public function addExtensions(... args):void

Add one or more file extensions (without leading dot) that identify the supported data types. Used by 'canHandle' to figure out if the factory is suitable for an asset reference.

Parameters

... args

addMimeTypes()method 
public function addMimeTypes(... args):void

Add one or more mime types that identify the supported data types. Used by 'canHandle' to figure out if the factory is suitable for an asset reference.

Parameters

... args

canHandle()method 
public function canHandle(reference:AssetReference):Boolean

Returns 'true' if this factory can handle the given reference. The default implementation checks if extension and/or mime type of the reference match those of the factory.

Parameters

reference:AssetReference

Returns
Boolean
create()method 
public function create(reference:AssetReference, helper:AssetFactoryHelper, onComplete:Function, onError:Function):void

This method will only be called if 'canHandle' returned 'true' for the given reference. It's responsible for creating at least one concrete asset and passing it to 'onComplete'.

Parameters

reference:AssetReference — The asset to be created. If a local or remote URL is referenced, it will already have been loaded, and 'data' will contain a ByteArray.
 
helper:AssetFactoryHelper — Contains useful utility methods to be used by the factory. Look at the class documentation for more information.
 
onComplete:Function — To be called when loading is successful. 'type' parameter is optional.
function(name:String, asset:Object, type:String):void;
 
onError:Function — To be called when creation fails for some reason. Do not call 'onComplete' when that happens.
function(error:String):void

getExtensions()method 
public function getExtensions(out:Vector.<String> = null):Vector.<String>

Returns the file extensions this factory supports.

Parameters

out:Vector.<String> (default = null)

Returns
Vector.<String>
getMimeTypes()method 
public function getMimeTypes(out:Vector.<String> = null):Vector.<String>

Returns the mime types this factory supports.

Parameters

out:Vector.<String> (default = null)

Returns
Vector.<String>