Loader
The Loader object is used to load image(JPG, PNG, or GIF) files. Use the load() method to initiate loading. The loaded display object is added as a child of the Loader object.
Use the URLLoader object to load text or binary data.
The Loader object overrides the following methods that it inherits, because a Loader object can only have one child display object - the display object that it loads. Calling the following methods throws an exception: addChild(), addChildAt(), removeChild(), removeChildAt(), and setChildIndex(). To remove a loaded display object, you must remove the Loader object from its parent DisplayObjectContainer child array.
Inherited from Sprite -> DisplayObjectContainer -> InteractiveObject -> DisplayObject -> EventDispatcher
Loader can be created with method new:
Lib.Media.Display.Loader.new() |
Creates a Loader object that you can use to load files, such as JPEG, GIF, or PNG files. Call the load() method to load the asset as a child of the Loader instance. You can then add the Loader object to the display list(for instance, by using the addChild() method of a DisplayObjectContainer instance). The asset appears on the Stage as it loads. You can also use a Loader instance "offlist," that is without adding it to a display object container on the display list. To detect when the file is finished loading, you can use the events of the LoaderInfo object associated with the contentLoaderInfo property of the Loader object. In the offlist mode, a Loader instance might also be used to load a file that contains assets. Again, you can use the LoaderInfo object event notifications to detect when the file are finished loading. At that point, the application can start using the media assets in the library. To determine the status of a Loader object, monitor the following events that the LoaderInfo object associated with the contentLoaderInfo property of the Loader object: The open event is dispatched when loading begins. The ioError or securityError event is dispatched if the file cannot be loaded or if an error occured during the load process. The progress event fires continuously while the file is being loaded. The complete event is dispatched when a file completes downloading, but before the loaded movie clip's methods and properties are available. The init event is dispatched after the properties and methods of the loaded file are accessible, so you can begin manipulating the loaded file. This event is dispatched before the complete handler. In streaming files, the init event can occur significantly earlier than the complete event. For most purposes, use the init handler. |
created Loader object has properties:
content |
Contains the image(JPG, PNG, or GIF) file that was loaded by using the load() or loadBytes() methods. |
DisplayObject or nil (read-only) |
contentLoaderInfo |
Returns a LoaderInfo object corresponding to the object being loaded. LoaderInfo objects are shared between the Loader object and the loaded content object. The LoaderInfo object supplies loading progress information and statistics about the loaded file. Events related to the load are dispatched by the LoaderInfo object referenced by the contentLoaderInfo property of the Loader object. The contentLoaderInfo property is set to a valid LoaderInfo object, even before the content is loaded, so that you can add event listeners to the object prior to the load. |
LoaderInfo object or nil (read-only) |
methods:
load(request, context) |
Loads a JPEG, progressive JPEG, unanimated GIF, or PNG file into an object that is a child of this Loader object. If you load an animated GIF file, only the first frame is displayed. As the Loader object can contain only a single child, issuing a subsequent load() request terminates the previous request, if still pending, and commences a new load. A image loaded into a Loader object inherits the position, rotation, and scale properties of the parent display objects of the Loader object. Use the unload() method to remove movies or images loaded with this method, or to cancel a load operation that is in progress. |
request - URLRequest object with absolute or relative URL of the JPEG, GIF, or PNG file to be loaded. A relative path must be relative to the main app file. Absolute URLs must include the protocol reference, such as http:// or file:///. Filenames cannot include disk drive specifications. context - LoaderContext object, not supported, use nil value |
loadBytes(bytes, context) |
Loads from binary data stored in a ByteArray object. The loadBytes() method is asynchronous. You must wait for the "init" event before accessing the properties of a loaded object. |
bytes - A ByteArray object. The contents of the ByteArray can be any of the file formats supported by the Loader class: GIF, JPEG, or PNG. context - LoaderContext object, not supported, use nil value |
unload() |
Removes a child of this Loader object that was loaded by using the load() method. The property of the associated LoaderInfo object is reset to nil. The child is not necessarily destroyed because other objects might have references to it; however, it is no longer a child of the Loader object. |
|
Examples:
Events = Lib.Media.Events
Display = Lib.Media.Display
Net = Lib.Media.Net
loader1 = Display.Loader.new()
loader1.contentLoaderInfo.addEventListener(Events.Event.COMPLETE,
function(e)
local bmp1 = loader1.content
image1 = bmp1.bitmapData
end, false, 0, false)
root = Lib.Media.FileSystem.File.applicationStorageDirectory.nativePath
loader1.load(Net.URLRequest.new(root.."/Image.jpg"), nil)
Created with the Personal Edition of HelpNDoc: News and information about help authoring tools and software