To load an image asset use the
loadAsset() function passing an
Asset reference and a constructed
To load an asset you firstly need to have retrieved an
Asset reference from the extension.
Once you have a reference to the asset you wish to load, you will construct an
AssetRequest to specify the version of the asset to retrieve. This allows you to load a version of the asset that suits your usage specifying the width and height of the loaded data. This is so you don't have to allocate memory to accomodate the entire image and additionally this ensures that the loading and resizing of the image data is done as quickly as possible, reducing the load on the cpu of the device.
To construct an
AssetRequest use the properties on the
AssetRequest class. You must at least set a width and height to be used.
Once you have your
AssetRequest you can initiate the load:
loadAsset() call when initiated successfully will dispatch an event when complete:
AssetEvent.ASSET_LOADED: If the load was successfully completed;
AssetEvent.ASSET_ERROR: If an error occurred during the load
To simplify creating requests there are some common preset requests that you may wish to use.
THUMBNAIL: Returns a thumbnail representation of the asset. The size of the thumbnail is the appropriate size for the platform, and in the correct orientation.
ASPECT_RATIO_THUMBNAIL: This representation contains an image with an aspect ratio thumbnail of the asset. The size of the thumbnail is the appropriate size for the platform, and in the correct orientation.
FULL_RESOLUTION: This representation contains the biggest, best representation available. Use this mode sparingly as it will require a significant amount of memory.
DISPLAY_RESOLUTION: This request will load an image that is big enough to cover the entire device screen.
To use these presets simply pass the preset to the
loadAsset() function instead of a constructed request:
Historical reference only - DO NOT USE this functionality anymore
Once your user has selected an asset you can then load the asset from the device.
Image assets can be loaded into a
BitmapData structure using the
The example below shows loading an image Asset using this method: