nme.display.LoaderInfo

type
class
extends
nme.events.EventDispatcher
available in
nme
The LoaderInfo class provides information about a loaded SWF file or a loaded image file(JPEG, GIF, or PNG). LoaderInfo objects are available for any display object. The information provided includes load progress, the URLs of the loader and loaded content, the number of bytes total for the media, and the nominal height and width of the media.

You can access LoaderInfo objects in two ways:

The contentLoaderInfo property of a Loader object provides information about the content that the Loader object is loading, whereas the loaderInfo property of a DisplayObject provides information about the root SWF file for that display object.

When you use a Loader object to load a display object(such as a SWF file or a bitmap), the loaderInfo property of the display object is the same as the contentLoaderInfo property of the Loader object(DisplayObject.loaderInfo = Loader.contentLoaderInfo). Because the instance of the main class of the SWF file has no Loader object, the loaderInfo property is the only way to access the LoaderInfo for the instance of the main class of the SWF file.

The following diagram shows the different uses of the LoaderInfo object - for the instance of the main class of the SWF file, for the contentLoaderInfo property of a Loader object, and for the loaderInfo property of a loaded object:

When a loading operation is not complete, some properties of the contentLoaderInfo property of a Loader object are not available. You can obtain some properties, such as bytesLoaded, bytesTotal, url, loaderURL, and applicationDomain. When the loaderInfo object dispatches the init event, you can access all properties of the loaderInfo object and the loaded image or SWF file.

Note: All properties of LoaderInfo objects are read-only.

The EventDispatcher.dispatchEvent() method is not applicable to LoaderInfo objects. If you call dispatchEvent() on a LoaderInfo object, an IllegalOperationError exception is thrown.

Static Methods

getLoaderInfoByDefinition(object : Dynamic) : LoaderInfo

parameters
object The object for which you want to get an associated LoaderInfo object.
returns
The associated LoaderInfo object. Returns null when called in non-debugger builds(or when debugging is not enabled) or if the referenced object does not have an associated LoaderInfo object(such as some objects used by the AIR runtime).
throws
SecurityError The caller is not running in the local trusted sandbox.
Returns the LoaderInfo object associated with a SWF file defined as an object.

Instance Variables hide inherited show inherited

bytes(default,null) : nme.utils.ByteArray

The bytes associated with a LoaderInfo object.

bytesLoaded(default,null) : Int

The number of bytes that are loaded for the media. When this number equals the value of bytesTotal, all of the bytes are loaded.

bytesTotal(default,null) : Int

The number of compressed bytes in the entire media file.

Before the first progress event is dispatched by this LoaderInfo object's corresponding Loader object, bytesTotal is 0. After the first progress event from the Loader object, bytesTotal reflects the actual number of bytes to be downloaded.

childAllowsParent(default,null) : Bool

Expresses the trust relationship from content(child) to the Loader (parent). If the child has allowed the parent access, true; otherwise, false. This property is set to true if the child object has called the allowDomain() method to grant permission to the parent domain or if a URL policy is loaded at the child domain that grants permission to the parent domain. If child and parent are in the same domain, this property is set to true.

For more information related to security, see the Flash Player Developer Center Topic: Security.

content(default,null) : DisplayObject

The loaded object associated with this LoaderInfo object.

contentType(default,null) : String

The MIME type of the loaded file. The value is null if not enough of the file has loaded in order to determine the type. The following list gives the possible values:
  • "application/x-shockwave-flash"
  • "image/jpeg"
  • "image/gif"
  • "image/png"

frameRate(default,null) : Float

The nominal frame rate, in frames per second, of the loaded SWF file. This number is often an integer, but need not be.

This value may differ from the actual frame rate in use. Flash Player or Adobe AIR only uses a single frame rate for all loaded SWF files at any one time, and this frame rate is determined by the nominal frame rate of the main SWF file. Also, the main frame rate may not be able to be achieved, depending on hardware, sound synchronization, and other factors.

height(default,null) : Int

The nominal height of the loaded file. This value might differ from the actual height at which the content is displayed, since the loaded content or its parent display objects might be scaled.

isURLInaccessible : Bool

metadata
:require
flash10_1
Indicates if the LoaderInfo.url property has been truncated. When the isURLInaccessible value is true the LoaderInfo.url value is only the domain of the final URL from which the content loaded. For example, the property is truncated if the content is loaded from http://www.adobe.com/assets/hello.swf, and the LoaderInfo.url property has the value http://www.adobe.com. The isURLInaccessible value is true only when all of the following are also true:
  • An HTTP redirect occurred while loading the content.
  • The SWF file calling Loader.load() is from a different domain than the content's final URL.
  • The SWF file calling Loader.load() does not have permission to access the content. Permission is granted to access the content the same way permission is granted for BitmapData.draw(): call Security.allowDomain() to access a SWF file(or for non-SWF file content, establish a policy file and use the LoaderContext.checkPolicyFile property).

Note: The isURLInaccessible property was added for Flash Player 10.1 and AIR 2.0. However, this property is made available to SWF files of all versions when the Flash runtime supports it. So, using some authoring tools in "strict mode" causes a compilation error. To work around the error use the indirect syntax myLoaderInfo"isURLInaccessible", or disable strict mode. If you are using Flash Professional CS5 or Flex SDK 4.1, you can use and compile this API for runtimes released before Flash Player 10.1 and AIR 2.

For application content in AIR, the value of this property is always false.

loader(default,null) : Loader

The Loader object associated with this LoaderInfo object. If this LoaderInfo object is the loaderInfo property of the instance of the main class of the SWF file, no Loader object is associated.

loaderURL(default,null) : String

The URL of the SWF file that initiated the loading of the media described by this LoaderInfo object. For the instance of the main class of the SWF file, this URL is the same as the SWF file's own URL.

parameters(default,null) : Dynamic<String>

An object that contains name-value pairs that represent the parameters provided to the loaded SWF file.

You can use a for-in loop to extract all the names and values from the parameters object.

The two sources of parameters are: the query string in the URL of the main SWF file, and the value of the FlashVars HTML parameter (this affects only the main SWF file).

The parameters property replaces the ActionScript 1.0 and 2.0 technique of providing SWF file parameters as properties of the main timeline.

The value of the parameters property is null for Loader objects that contain SWF files that use ActionScript 1.0 or 2.0. It is only non-null for Loader objects that contain SWF files that use ActionScript 3.0.

parentAllowsChild(default,null) : Bool

Expresses the trust relationship from Loader(parent) to the content (child). If the parent has allowed the child access, true; otherwise, false. This property is set to true if the parent object called the allowDomain() method to grant permission to the child domain or if a URL policy file is loaded at the parent domain granting permission to the child domain. If child and parent are in the same domain, this property is set to true.

For more information related to security, see the Flash Player Developer Center Topic: Security.

sameDomain(default,null) : Bool

Expresses the domain relationship between the loader and the content: true if they have the same origin domain; false otherwise.

sharedEvents(default,null) : nme.events.EventDispatcher

An EventDispatcher instance that can be used to exchange events across security boundaries. Even when the Loader object and the loaded content originate from security domains that do not trust one another, both can access sharedEvents and send and receive events via this object.

swfVersion(default,null) : Int

The file format version of the loaded SWF file. The file format is specified using the enumerations in the SWFVersion class, such as SWFVersion.FLASH7 and SWFVersion.FLASH9.

url(default,null) : String

The URL of the media being loaded.

Before the first progress event is dispatched by this LoaderInfo object's corresponding Loader object, the value of the url property might reflect only the initial URL specified in the call to the load() method of the Loader object. After the first progress event, the url property reflects the media's final URL, after any redirects and relative URLs are resolved.

In some cases, the value of the url property is truncated; see the isURLInaccessible property for details.

width(default,null) : Int

The nominal width of the loaded content. This value might differ from the actual width at which the content is displayed, since the loaded content or its parent display objects might be scaled.

Instance Methods hide inherited show inherited

addEventListener(type : String, listener : Dynamic -> Void, ?useCapture : Bool, ?priority : Int, ?useWeakReference : Bool) : Void

parameters
type The type of event.
useCapture Determines whether the listener works in the capture phase or the target and bubbling phases. If useCapture is set to true, the listener processes the event only during the capture phase and not in the target or bubbling phase. If useCapture is false, the listener processes the event only during the target or bubbling phase. To listen for the event in all three phases, call addEventListener twice, once with useCapture set to true, then again with useCapture set to false.
priority The priority level of the event listener. The priority is designated by a signed 32-bit integer. The higher the number, the higher the priority. All listeners with priority n are processed before listeners of priority n-1. If two or more listeners share the same priority, they are processed in the order in which they were added. The default priority is 0.
useWeakReference Determines whether the reference to the listener is strong or weak. A strong reference(the default) prevents your listener from being garbage-collected. A weak reference does not.

Class-level member functions are not subject to garbage collection, so you can set useWeakReference to true for class-level member functions without subjecting them to garbage collection. If you set useWeakReference to true for a listener that is a nested inner function, the function will be garbage-collected and no longer persistent. If you create references to the inner function(save it in another variable) then it is not garbage-collected and stays persistent.

throws
ArgumentError The listener specified is not a function.
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. You can register event listeners on all nodes in the display list for a specific type of event, phase, and priority.

After you successfully register an event listener, you cannot change its priority through additional calls to addEventListener(). To change a listener's priority, you must first call removeListener(). Then you can register the listener again with the new priority level.

Keep in mind that after the listener is registered, subsequent calls to addEventListener() with a different type or useCapture value result in the creation of a separate listener registration. For example, if you first register a listener with useCapture set to true, it listens only during the capture phase. If you call addEventListener() again using the same listener object, but with useCapture set to false, you have two separate listeners: one that listens during the capture phase and another that listens during the target and bubbling phases.

You cannot register an event listener for only the target phase or the bubbling phase. Those phases are coupled during registration because bubbling applies only to the ancestors of the target node.

If you no longer need an event listener, remove it by calling removeEventListener(), or memory problems could result. Event listeners are not automatically removed from memory because the garbage collector does not remove the listener as long as the dispatching object exists(unless the useWeakReference parameter is set to true).

Copying an EventDispatcher instance does not copy the event listeners attached to it.(If your newly created node needs an event listener, you must attach the listener after creating the node.) However, if you move an EventDispatcher instance, the event listeners attached to it move along with it.

If the event listener is being registered on a node while an event is being processed on this node, the event listener is not triggered during the current phase but can be triggered during a later phase in the event flow, such as the bubbling phase.

If an event listener is removed from a node while an event is being processed on the node, it is still triggered by the current actions. After it is removed, the event listener is never invoked again(unless registered again for future processing).

dispatchEvent(event : Event) : Bool

parameters
event The Event object that is dispatched into the event flow. If the event is being redispatched, a clone of the event is created automatically. After an event is dispatched, its target property cannot be changed, so you must create a new copy of the event for redispatching to work.
returns
A value of true if the event was successfully dispatched. A value of false indicates failure or that preventDefault() was called on the event.
throws
Error The event dispatch recursion limit has been reached.
Dispatches an event into the event flow. The event target is the EventDispatcher object upon which the dispatchEvent() method is called.

hasEventListener(type : String) : Bool

parameters
type The type of event.
returns
A value of true if a listener of the specified type is registered; false otherwise.
Checks whether the EventDispatcher object has any listeners registered for a specific type of event. This allows you to determine where an EventDispatcher object has altered handling of an event type in the event flow hierarchy. To determine whether a specific event type actually triggers an event listener, use willTrigger().

The difference between hasEventListener() and willTrigger() is that hasEventListener() examines only the object to which it belongs, whereas willTrigger() examines the entire event flow for the event specified by the type parameter.

When hasEventListener() is called from a LoaderInfo object, only the listeners that the caller can access are considered.

removeEventListener(type : String, listener : Dynamic -> Void, ?useCapture : Bool) : Void

parameters
type The type of event.
useCapture Specifies whether the listener was registered for the capture phase or the target and bubbling phases. If the listener was registered for both the capture phase and the target and bubbling phases, two calls to removeEventListener() are required to remove both, one call with useCapture() set to true, and another call with useCapture() set to false.
Removes a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect.

toString() : String

willTrigger(type : String) : Bool

parameters
type The type of event.
returns
A value of true if a listener of the specified type will be triggered; false otherwise.
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. This method returns true if an event listener is triggered during any phase of the event flow when an event of the specified type is dispatched to this EventDispatcher object or any of its descendants.

The difference between the hasEventListener() and the willTrigger() methods is that hasEventListener() examines only the object to which it belongs, whereas the willTrigger() method examines the entire event flow for the event specified by the type parameter.

When willTrigger() is called from a LoaderInfo object, only the listeners that the caller can access are considered.