| Package | flash.display | 
| Class | public class Loader | 
| Inheritance | Loader  DisplayObjectContainer  InteractiveObject  DisplayObject  EventDispatcher  Object | 
load() method to initiate loading. The loaded display object is added as a child 
 of the Loader object.
  Use the URLLoader class to load text or binary data.
The Loader class 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. 
Note: The ActionScript 2.0 MovieClipLoader and LoadVars classes are not used in ActionScript 3.0. The Loader and URLLoader classes replace them.
When you use the Loader class, consider the Flash Player and Adobe AIR security model:
System.allowDomain() or  
 the System.allowInsecureDomain() method in the loaded content file.However, in the Apollo runtime, content in the application security sandbox (content
 installed with the Apollo application) are not restricted by these security limitations.
For more information, see the following:
When loading a SWF file from an untrusted source (such as a domain other than that of the Loader object's root SWF file), you may want to define a mask for the Loader object, to prevent the loaded content (which is a child of the Loader object) from drawing to portions of the Stage outside of that mask, as shown in the following code:
import flash.display.*; import flash.net.URLRequest; var rect:Shape = new Shape(); rect.graphics.beginFill(0xFFFFFF); rect.graphics.drawRect(0, 0, 100, 100); rect.graphics.endFill(); addChild(rect); var ldr:Loader = new Loader(); ldr.mask = rect; var url:String = "http://www.unknown.example.com/content.swf"; var urlReq:URLRequest = new URLRequest(url); ldr.load(urlReq); addChild(ldr);
See also
| Property | Defined By | ||
|---|---|---|---|
|  | accessibilityProperties : AccessibilityProperties 
     The current accessibility options for this display object. | DisplayObject | |
|  | alpha : Number 
     Indicates the alpha transparency value of the object specified. | DisplayObject | |
|  | blendMode : String 
     A value from the BlendMode class that specifies which blend mode to use. | DisplayObject | |
|  | cacheAsBitmap : Boolean 
     If set to true, Flash Player or Adobe AIR caches an internal bitmap representation of the
     display object. | DisplayObject | |
|  | constructor : Object 
  A reference to the class object or constructor function for a given object instance. | Object | |
| content : DisplayObject [read-only] 
  Contains the root display object of the SWF file or image (JPG, PNG, or GIF) 
     file that was loaded by using the load() or loadBytes() methods. | Loader | ||
| contentLoaderInfo : LoaderInfo [read-only] 
  Returns a LoaderInfo object corresponding to the object being loaded. | Loader | ||
|  | contextMenu : NativeMenu  
  Specifies the context menu associated with this object. | InteractiveObject | |
|  | doubleClickEnabled : Boolean  
  Specifies whether the object receives doubleClick events. | InteractiveObject | |
|  | filters : Array 
     An indexed array that contains each filter object currently associated with the display object. | DisplayObject | |
|  | focusRect : Object  
  Specifies whether this object displays a focus rectangle. | InteractiveObject | |
|  | height : Number 
     Indicates the height of the display object, in pixels. | DisplayObject | |
|  | loaderInfo : LoaderInfo [read-only] 
     Returns a LoaderInfo object containing information about loading the file
     to which this display object belongs. | DisplayObject | |
|  | mask : DisplayObject 
     The calling display object is masked by the specified mask object. | DisplayObject | |
|  | mouseChildren : Boolean 
  Determines whether or not the children of the object are mouse enabled. | DisplayObjectContainer | |
|  | mouseEnabled : Boolean  
  Specifies whether this object receives mouse messages. | InteractiveObject | |
|  | mouseX : Number [read-only] 
     Indicates the x coordinate of the mouse position, in pixels. | DisplayObject | |
|  | mouseY : Number [read-only] 
     Indicates the y coordinate of the mouse position, in pixels. | DisplayObject | |
|  | name : String 
     Indicates the instance name of the DisplayObject. | DisplayObject | |
|  | numChildren : int [read-only] 
  Returns the number of children of this object. | DisplayObjectContainer | |
|  | opaqueBackground : Object 
     Specifies whether the display object is opaque with a certain background color. | DisplayObject | |
|  | parent : DisplayObjectContainer [read-only] 
     Indicates the DisplayObjectContainer object that contains this display object. | DisplayObject | |
|  | prototype : Object [static] 
  A reference to the prototype object of a class or function object. | Object | |
|  | root : DisplayObject [read-only] 
     For a display object in a loaded SWF file, the root property is the 
     top-most display object in the portion of the display list's tree structure represented by that SWF file. | DisplayObject | |
|  | rotation : Number 
     Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation. | DisplayObject | |
|  | scale9Grid : Rectangle 
     The current scaling grid that is in effect. | DisplayObject | |
|  | scaleX : Number 
     Indicates the horizontal scale (percentage) of the object as applied from the registration point. | DisplayObject | |
|  | scaleY : Number 
     Indicates the vertical scale (percentage) of an object as applied from the registration point of the object. | DisplayObject | |
|  | scrollRect : Rectangle 
     The scroll rectangle bounds of the display object. | DisplayObject | |
|  | stage : Stage [read-only] 
     The Stage of the display object. | DisplayObject | |
|  | tabChildren : Boolean 
  Determines whether the children of the object are tab enabled. | DisplayObjectContainer | |
|  | tabEnabled : Boolean  
  Specifies whether this object is in the tab order. | InteractiveObject | |
|  | tabIndex : int  
     Specifies the tab ordering of objects in a SWF file. | InteractiveObject | |
|  | textSnapshot : TextSnapshot [read-only] 
     Returns a TextSnapshot object for this DisplayObjectContainer instance. | DisplayObjectContainer | |
|  | transform : Transform 
    An object with properties pertaining to a display object's matrix, color transform, and pixel bounds. | DisplayObject | |
|  | visible : Boolean 
     Whether or not the display object is visible. | DisplayObject | |
|  | width : Number 
     Indicates the width of the display object, in pixels. | DisplayObject | |
|  | x : Number 
     Indicates the x coordinate of the DisplayObject instance relative to the local coordinates of
     the parent DisplayObjectContainer. | DisplayObject | |
|  | y : Number 
     Indicates the y coordinate of the DisplayObject instance relative to the local coordinates of
     the parent DisplayObjectContainer. | DisplayObject | |
| Method | Defined By | ||
|---|---|---|---|
| 
Loader() 
  Creates a Loader object that you can use to load files, such as SWF, JPEG, GIF, or PNG files. | Loader | ||
|  | 
     Adds a child DisplayObject instance to this DisplayObjectContainer instance. | DisplayObjectContainer | |
|  | 
  Adds a child DisplayObject instance to this DisplayObjectContainer 
  instance. | DisplayObjectContainer | |
|  | 
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
 
 Registers an event listener object with an EventDispatcher object so that the listener 
 receives notification of an event. | EventDispatcher | |
|  | 
  Indicates whether the security restrictions 
  would cause any display objects to be omitted from the list returned by calling
  the DisplayObjectContainer.getObjectsUnderPoint() method
  with the specified point point. | DisplayObjectContainer | |
| 
  Cancels a load() method operation that is currently in progress for the Loader instance. | Loader | ||
|  | 
  Determines whether the specified display object is a child of the DisplayObjectContainer instance or
  the instance itself. | DisplayObjectContainer | |
|  | 
 Dispatches an event into the event flow. | EventDispatcher | |
|  | 
     Returns a rectangle that defines the area of the display object relative to the coordinate system
     of the targetCoordinateSpace object. | DisplayObject | |
|  | 
     Returns the child display object instance that exists at the specified index. | DisplayObjectContainer | |
|  | 
     Returns the child display object that exists with the specified name. | DisplayObjectContainer | |
|  | 
     Returns the index position of a child DisplayObject instance. | DisplayObjectContainer | |
|  | 
     Returns an array of objects that lie under the specified point and are children 
     (or grandchildren, and so on) of this DisplayObjectContainer instance. | DisplayObjectContainer | |
|  | 
    Returns a rectangle that defines the boundary of the display object, 
    based on the coordinate system defined by the targetCoordinateSpace 
    parameter, excluding any strokes on shapes. | DisplayObject | |
|  | 
     Converts the point object from the Stage (global) coordinates
     to the display object's (local) coordinates. | DisplayObject | |
|  | 
 Checks whether the EventDispatcher object has any listeners registered for a specific type 
 of event. | EventDispatcher | |
|  | 
  Indicates whether an object has a specified property defined. | Object | |
|  | 
     Evaluates the display object to see if it overlaps or intersects with the
     obj display object. | DisplayObject | |
|  | 
     Evaluates the display object to see if it overlaps or intersects with the
     point specified by the x and y parameters. | DisplayObject | |
|  | 
  Indicates whether an instance of the Object class is in the prototype chain of the object specified 
  as the parameter. | Object | |
| 
  Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into an object that is a child of 
  this Loader object. | Loader | ||
| 
  Loads from binary data stored in a ByteArray object. | Loader | ||
|  | 
     Converts the point object from the display object's (local) coordinates to the
     Stage (global) coordinates. | DisplayObject | |
|  | 
  Indicates whether the specified property exists and is enumerable. | Object | |
|  | 
  Removes the specified child DisplayObject instance from the child list of the DisplayObjectContainer instance. | DisplayObjectContainer | |
|  | 
  Removes a child DisplayObject from the specified index position in the child list of 
  the DisplayObjectContainer. | DisplayObjectContainer | |
|  | 
 Removes a listener from the EventDispatcher object. | EventDispatcher | |
|  | 
 Changes the  position of an existing child in the display object container. | DisplayObjectContainer | |
|  | 
     Sets the availability of a dynamic property for loop operations. | Object | |
|  | 
  Swaps the z-order (front-to-back order) of the two specified child objects. | DisplayObjectContainer | |
|  | 
  Swaps the z-order (front-to-back order) of the child objects at the two specified index positions in the 
  child list. | DisplayObjectContainer | |
|  | 
  Returns the string representation of the specified object. | Object | |
| 
  Removes a child of this Loader object that was loaded by using the load() method. | Loader | ||
|  | 
  Returns the primitive value of the specified object. | Object | |
|  | 
 Checks whether an event listener is registered with this EventDispatcher object or any of 
 its ancestors for the specified event type. | EventDispatcher | |
| content | property | 
content:DisplayObject  [read-only] 
  Contains the root display object of the SWF file or image (JPG, PNG, or GIF) 
     file that was loaded by using the load() or loadBytes() methods.
    
    public function get content():DisplayObject
| SecurityError — The loaded SWF file or image file belongs to a security 
  sandbox to which you do not have access. For a loaded SWF file, you can avoid this situation by having
  the file call theSecurity.allowDomain()method or by having the loading file specify aloaderContextparameter with itssecurityDomainproperty set toSecurityDomain.currentDomainwhen you call theload()orloadBytes()method. | 
See also
| contentLoaderInfo | property | 
contentLoaderInfo:LoaderInfo  [read-only] 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.
    public function get contentLoaderInfo():LoaderInfo
See also
| Loader | () | Constructor | 
public function Loader()
  Creates a Loader object that you can use to load files, such as SWF, 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. In this mode, the Loader instance might be used to load a SWF file that contains additional modules of an application.
To detect when the SWF file is finished loading, you can use the events of the LoaderInfo  
  object associated with the contentLoaderInfo property of the Loader object.
  At that point, the code in the module SWF file can be executed to initialize and start the module.
  In the offlist mode, a Loader instance might also be used to load a SWF file that contains components or 
  media assets. Again, you can use the LoaderInfo object event notifications to detect when the 
  components are finished loading. At that point, the application can start using the components 
  and media assets in the library of the SWF file by instantiating the ActionScript 3.0 classes that represent 
  those components and assets.
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:
open event is dispatched when loading begins.ioError or securityError event is dispatched if the file 
  cannot be loaded or if an error occured during the load process. progress event fires continuously while the file is being loaded.complete event is dispatched when a file completes downloading, but before
  the loaded movie clip's methods and properties are available. init event is dispatched after the properties and methods of the loaded SWF file
  are accessible, so you can begin manipulating the loaded SWF file. 
  This event is dispatched before the complete handler. In streaming SWF files, 
  the init event can occur significantly earlier than the complete event. 
  For most purposes, use the init handler.See also
| close | () | method | 
public function close():void
  Cancels a load() method operation that is currently in progress for the Loader instance.
  
  
See also
| load | () | method | 
public function load(request:URLRequest, context:LoaderContext = null):void
  Loads a SWF, 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 SWF file or 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.
When you use the load() method, consider the Flash Player or Adobe AIR security model: 
Security.allowDomain() method in the loaded content file. allowNetworking 
  parameter of the the object and embed tags in the HTML 
  page that contains the SWF content.However, in the Apollo runtime, content in the application security sandbox (content
  installed with the Apollo application) are not restricted by these security limitations.
For more information, see the following:
Parameters
| request:URLRequest—  The absolute or relative URL of the SWF, JPEG, GIF, or PNG file to be loaded. A 
  relative path must be relative to the main SWF file. Absolute URLs must include the 
  protocol reference, such as http:// or file:///. Filenames cannot include disk drive 
  specifications. | |
| context:LoaderContext(default =null)— A LoaderContext object, which has properties that define the following:
 For complete details, see the description of the properties in the LoaderContext class. | 
| complete:— Dispatched by the associated LoaderInfo object when the file has completed loading. 
  Thecompleteevent is always dispatched after theinitevent. | |
| httpStatus:— Dispatched by the associated LoaderInfo object when a network request 
  is made over HTTP and the HTTP status code can be detected. | |
| init:— Dispatched by the associated LoaderInfo object when the properties and methods of 
  the loaded SWF file are accessible. Theinitevent always precedes thecompleteevent. | |
| ioError:— Dispatched by the associated LoaderInfo object when an input or output 
  error occurs that causes a load operation to fail. | |
| open:— Dispatched by the associated LoaderInfo object when the loading operation starts. | |
| progress:— Dispatched by the associated LoaderInfo object as data is received 
  while load operation progresses. | |
| unload:— Dispatched by the associated LoaderInfo object when a loaded object is removed. | 
| SecurityError — The value ofLoaderContext.securityDomainmust be eithernullorSecurityDomain.currentDomain.  This reflects the fact that you can only
  place the loaded media in its natural security sandbox or your own (the latter requires a
  policy file). | |
| SecurityError — Local SWF files may not set LoaderContext.securityDomain to anything
  other thannull.  It is not permitted to import non-local media into a local
  sandbox, or to place other local media in anything other than its natural sandbox. | |
| SecurityError — If theapplicationDomainorsecurityDomainproperties of thecontextparameter are from a disallowed domain. | |
| SecurityError — If a local SWF file is attempting to use thesecurityDomainproperty
  of thecontextparameter. | 
See also
| loadBytes | () | method | 
public function loadBytes(bytes:ByteArray, context:LoaderContext = null):void
Loads from binary data stored in a ByteArray object.
Parameters
| bytes:ByteArray— A ByteArray object. The contents of the ByteArray can be 
  any of the file formats supported by the Loader class: SWF, GIF, JPEG, or PNG. | |
| context:LoaderContext(default =null)— A LoaderContext object. Only theapplicationDomainproperty 
  of the LoaderContext object applies; thecheckPolicyFileandsecurityDomainproperties of the LoaderContext object do not apply. | 
| ArgumentError — If thelengthproperty of the ByteArray object is not
  greater than 0. | |
| IllegalOperationError — If thecheckPolicyFileorsecurityDomainproperty of thecontextparameter are non-null. | |
| SecurityError — If the providedapplicationDomainproperty of thecontextproperty is from a disallowed domain. | 
See also
| unload | () | method | 
public function unload():void
  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 null.  
  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.
    
As a best practice, before you unload a child SWF file, you should explicitly
  close any streams in the child SWF file's objects, such as LocalConnection, NetConnection,
     NetStream, and Sound objects. Otherwise, audio in the child SWF file might continue to play, even
  though the child SWF file was unloaded. To close streams in the child SWF file, add an event listener
  to the child that listens for the unload event. When the parent calls
  Loader.unload(), the unload event is dispatched to the child.
  The following code shows how you might do this:
function closeAllStreams(evt:Event) { 
    myNetStream.close();
    mySound.close();
    myNetConnection.close();
    myLocalConnection.close();
}
myMovieClip.loaderInfo.addEventListener(Event.UNLOAD, closeAllStreams);
See also
url property is created, which is the location and name of the image fileLoaderExample constructor, a new Loader object named loader is
  created, which is then passed to the configureListeners() method, described in step 3.request, with url passed so that the file name and location are known.request object is passed to the loader object's 
  load() method, which loads the image onto the display list.clickHandler event listener is registered for the click event on the loader.
      After a mouse click, the loaded image is unloaded.configureListeners() method adds seven event listeners by using the following methods:
  completeHandler() method executes when the image finishes loading.httpStatusHandler() method executes if the image is not loaded 
      locally and only if the network request is made available and the Flash Player can detect it.initHandler() method executes before the completeHandler() 
      method and after the progressHandler() method. Generally, the init 
      event is more useful when loading SWF files.ioErrorHandler() method executes if the image file is not available or not 
      accessible.openHandler() method executes when the image file is first opened.progressHandler() method executes when the image file starts to load and 
      again when the image is finished loading.unLoadHandler() method executes when the image is unloaded by using the 
      unload() method when the user clicks the image.Keep in mind the following requirements:
complete event 
  (and perhaps the ioError event) are sufficient when loading a local image.
package {
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLRequest;
    public class LoaderExample extends Sprite {
        private var url:String = "Image.gif";
        public function LoaderExample() {
            var loader:Loader = new Loader();
            configureListeners(loader.contentLoaderInfo);
            loader.addEventListener(MouseEvent.CLICK, clickHandler);
            var request:URLRequest = new URLRequest(url);
            loader.load(request);
            addChild(loader);
        }
        private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(Event.INIT, initHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(Event.UNLOAD, unLoadHandler);
        }
        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }
        private function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }
        private function initHandler(event:Event):void {
            trace("initHandler: " + event);
        }
        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }
        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }
        private function progressHandler(event:ProgressEvent):void {
            trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }
        private function unLoadHandler(event:Event):void {
            trace("unLoadHandler: " + event);
        }
        private function clickHandler(event:MouseEvent):void {
            trace("clickHandler: " + event);
            var loader:Loader = Loader(event.target);
            loader.unload();
        }
    }
}