import {EventDispatcher} from "../events/EventDispatcher"; import {Loader} from "../library/Loader"; import {AssetBase} from "../library/AssetBase"; import {ByteArray} from "../utils/ByteArray"; /** * The LoaderInfo export 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:
* *contentLoaderInfo property of a flash.display.Loader
* object - The contentLoaderInfo property is always available
* for any Loader object. For a Loader object that has not called the
* load() or loadBytes() method, or that has not
* sufficiently loaded, attempting to access many of the properties of the
* contentLoaderInfo property throws an error.loaderInfo property of a display object. 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 export 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 export class of
* the SWF file.
The following diagram shows the different uses of the LoaderInfo
* object - for the instance of the main export 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.
complete event is always dispatched after
* the init event. The init event
* is dispatched when the object is ready to access, though
* the content may still be downloading.
* @event httpStatus Dispatched when a network request is made over HTTP and
* an HTTP status code can be detected.
* @event init Dispatched when the properties and methods of a loaded
* SWF file are accessible and ready for use. The content,
* however, can still be downloading. A LoaderInfo object
* dispatches the init event when the following
* conditions exist:
* For example, an Event.INIT is dispatched
* when the first frame of a movie or animation is loaded.
* The movie is then accessible and can be added to the
* display list. The complete movie, however, can take
* longer to download. The Event.COMPLETE is
* only dispatched once the full movie is loaded.
The init event always precedes the
* complete event.
unload()
* method of the Loader object, or when a second load is
* performed by the same Loader object and the original
* content is removed prior to the load beginning.
*/
export class LoaderInfo extends EventDispatcher
{
private _bytes:ByteArray;
private _bytesLoaded:number;
private _bytesTotal:number;
private _content:AssetBase;
private _contentType:string;
private _loader:Loader;
private _url:string;
/**
* The bytes associated with a LoaderInfo object.
*
* @throws SecurityError If the object accessing this API is prevented from
* accessing the loaded object due to security
* restrictions. This situation can occur, for
* instance, when a Loader object attempts to access
* the contentLoaderInfo.content property
* and it is not granted security permission to access
* the loaded content.
*
* For more information related to security, see the * Flash Player Developer Center Topic: Security.
*/ public get bytes():ByteArray { return this._bytes; } /** * The number of bytes that are loaded for the media. When this number equals * the value ofbytesTotal, all of the bytes are loaded.
*/
public get bytesLoaded():number /*int*/
{
return this._bytesLoaded;
}
/**
* 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.
contentLoaderInfo.content property
* and it is not granted security permission to access
* the loaded content.
*
* For more information related to security, see the * Flash Player Developer Center Topic: Security.
*/ public get content():AssetBase { return this._content; } /** * The MIME type of the loaded file. The value isnull 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"loaderInfo property of the instance
* of the main export class of the SWF file, no Loader object is associated.
*
* @throws SecurityError If the object accessing this API is prevented from
* accessing the Loader object because of security
* restrictions. This can occur, for instance, when a
* loaded SWF file attempts to access its
* loaderInfo.loader property and it is
* not granted security permission to access the
* loading SWF file.
*
* For more information related to security, see the * Flash Player Developer Center Topic: Security.
*/ public get loader():Loader { return this._loader; } /** * 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.