Packagecom.apdevblog.load
Classpublic class PreLoader
InheritancePreLoader Inheritance flash.display.Sprite

Runtime Versions : AIR 1.0, Flash Player 9

PreLoader works similar to the Loader class (loads SWF, GIF, JPG and PNG) but has an integrated loader queue and some conveniences.

Example implementation:

     var img:PreLoader = new PreLoader();
     img.addEventListener(ProgressEvent.PROGRESS, _onImgProgress);
     img.addEventListener(Event.COMPLETE, _onImgLoaded);
     img.load("image.jpg");
     addChild(img);
     
     function _onImgProgress(event : ProgressEvent)
     {
       var perc:Number = event.bytesLoaded / event.bytesTotal;
       trace(perc);
     }
     
     function _onImgLoaded(event : Event)
     {
       trace("image loaded");
     }
     

PreLoader communicates with the static class PreloadProxy, which is taking care of the actual loader queue. Only one loading process at a time is executed.

A typical use would be to add all stuff needed to load in an order that makes somehow sense (i.e. intro.swf, home.swf, image1.png, image2.png, image3.png) with the standard method load. Read a typical scenario.

During runtime you can prioritize a loading process by using loadNext(), loadAfter(), and loadImmidately().

The PreLoader fires the exact same events as the standard Loader. Just make sure you set the listeners directly to the PreLoader instead of contentLoaderInfo.

Example:

     // set listener with Loader
     
     var img:Loader = new Loader();
     img.contentLoaderInfo.addEventListener(Event.COMPLETE, _onImgLoaded);
     
     // set listener with PreLoader
       var img:PreLoader = new PreLoader();
     img.addEventListener(Event.COMPLETE, _onImgLoaded);
     

See also

PreloadProxy


Public Properties
 PropertyDefined By
  autoUnload : Boolean
If true, unload is called, when the PreLoader is removed from stage (to prepare the Loader for garbage collection).
PreLoader
  content : DisplayObject
[read-only] returns the content DisplayObject of the containt loader.
PreLoader
  contentLoaderInfo : LoaderInfo
[read-only] returns the LoaderInfo Similar to Loader.contentLoaderInfo.
PreLoader
  isImage : Boolean
[read-only] returns whether the PreLoader loads an image
PreLoader
  isInit : Boolean
[read-only] returns if is init.
PreLoader
  isLoaded : Boolean
[read-only] returns if the loading is complete.
PreLoader
  loader : Loader
[read-only] returns the Loader.
PreLoader
  loaderContext : LoaderContext
gets and sets the LoaderContext of the load process.
PreLoader
  scale : Number
[write-only] sets scaleX and scaleY in one go
PreLoader
  smooth : Boolean
gets and sets whether the PreLoaded should be smoothed when scaled (this applies only when loading image).
PreLoader
  url : String
[read-only] returns the url (if passed already).
PreLoader
  urlRequest : URLRequest
[read-only] returns the URLRequest (if passed already).
PreLoader
Public Methods
 MethodDefined By
  
Constructor
PreLoader
  
closeLoad():void
stops the load process (if currently loading) or removes load request from queue (if in queue).
PreLoader
  
load(urlStringOrURLRequest:*):void
loads the passed url (or URLRequest) by adding it to the end of the loader queue.
PreLoader
  
loadAfter(urlStringOrURLRequest:*, beforePreLoader:PreLoader):void
Loads the passed url (or URLRequest) by adding it to the loader queue after the passed PreLoader object.
PreLoader
  
loadImmediately(urlStringOrURLRequest:*):void
loads the passed url (or URLRequest) by canceling the current load and starts the load immediately.
PreLoader
  
loadNext(urlStringOrURLRequest:*):void
loads the passed url (or URLRequest) by adding it after the current loading request.
PreLoader
  
toString():String
returns [PreLoader] thePassedUrl (i.e.
PreLoader
  
unload():void
unloads the loader.
PreLoader
Property Detail
autoUnloadproperty
autoUnload:Boolean  [read-write]

If true, unload is called, when the PreLoader is removed from stage (to prepare the Loader for garbage collection).


Implementation
    public function get autoUnload():Boolean
    public function set autoUnload(value:Boolean):void
contentproperty 
content:DisplayObject  [read-only]

returns the content DisplayObject of the containt loader.


Implementation
    public function get content():DisplayObject

See also

flash.display.Loader.content
contentLoaderInfoproperty 
contentLoaderInfo:LoaderInfo  [read-only]

returns the LoaderInfo

Similar to Loader.contentLoaderInfo.


Implementation
    public function get contentLoaderInfo():LoaderInfo

See also

flash.display.LoaderInfo
flash.display.Loader.contentLoaderInfo
isImageproperty 
isImage:Boolean  [read-only]

returns whether the PreLoader loads an image


Implementation
    public function get isImage():Boolean
isInitproperty 
isInit:Boolean  [read-only]

returns if is init.

Is set to true, when onLoadInit is received.


Implementation
    public function get isInit():Boolean
isLoadedproperty 
isLoaded:Boolean  [read-only]

returns if the loading is complete.


Implementation
    public function get isLoaded():Boolean
loaderproperty 
loader:Loader  [read-only]

returns the Loader.


Implementation
    public function get loader():Loader
loaderContextproperty 
loaderContext:LoaderContext  [read-write]

gets and sets the LoaderContext of the load process.

Might be needed when using the smooth option and loading images from a different domain.

Caution: Has to be set before load is called.


Implementation
    public function get loaderContext():LoaderContext
    public function set loaderContext(value:LoaderContext):void
scaleproperty 
scale:Number  [write-only]

sets scaleX and scaleY in one go


Implementation
    public function set scale(value:Number):void
smoothproperty 
smooth:Boolean  [read-write]

gets and sets whether the PreLoaded should be smoothed when scaled (this applies only when loading image).


Implementation
    public function get smooth():Boolean
    public function set smooth(value:Boolean):void
urlproperty 
url:String  [read-only]

returns the url (if passed already).


Implementation
    public function get url():String
urlRequestproperty 
urlRequest:URLRequest  [read-only]

returns the URLRequest (if passed already).

Note: If you passed a String to the load method the automaticly generated URLRequest will be returned.


Implementation
    public function get urlRequest():URLRequest
Constructor Detail
PreLoader()Constructor
public function PreLoader()

Constructor

Method Detail
closeLoad()method
public function closeLoad():void

stops the load process (if currently loading) or removes load request from queue (if in queue).

Note: closeLoad might or might not work locally. If you have problems using closeLoad locally test your project online.

load()method 
public function load(urlStringOrURLRequest:*):void

loads the passed url (or URLRequest) by adding it to the end of the loader queue.

Example:

         var img1:PreLoader = new PreLoader();
         img1.load("img1.jpg");
         
         var img2:PreLoader = new PreLoader();
         img2.load("img2.jpg");
         
         var img3:PreLoader = new PreLoader();
         img3.load("img3.jpg");
         
         var img4:PreLoader = new PreLoader();
         img4.load("img4.jpg");
         
         // now the queue looks like this:
         // img1.jpg, img2.jpg, img3.jpg, img4.jpg
         // where img1.jpg is currently loading
         

Parameters

urlStringOrURLRequest:* — url as String ("image.png") or URLRequest.

See also

loadAfter()method 
public function loadAfter(urlStringOrURLRequest:*, beforePreLoader:PreLoader):void

Loads the passed url (or URLRequest) by adding it to the loader queue after the passed PreLoader object.

This call will be ignored when its currently loading.

Example:

         var img1:PreLoader = new PreLoader();
         img1.load("img1.jpg");
         
         var img2:PreLoader = new PreLoader();
         img2.load("img2.jpg");
         
         var img3:PreLoader = new PreLoader();
         img3.loadAfter("img3.jpg", img1);
         
         var img4:PreLoader = new PreLoader();
         img4.loadAfter("img4.jpg", img3);
         
         // now the queue looks like this:
         // img1.jpg, img3.jpg, img4.jpg, img2.jpg
         // where img1.jpg is currently loading
         

Parameters

urlStringOrURLRequest:* — url as String ("image.png") or URLRequest.
 
beforePreLoader:PreLoaderPreLoader instance to queue urlStringOrURLRequest after

See also

loadImmediately()method 
public function loadImmediately(urlStringOrURLRequest:*):void

loads the passed url (or URLRequest) by canceling the current load and starts the load immediately.

This call will be ignored when its currently loading.

Example:

         var img1:PreLoader = new PreLoader();
         img1.load("img1.jpg");
         
         var img2:PreLoader = new PreLoader();
         img2.load("img2.jpg");
         
         var img3:PreLoader = new PreLoader();
         img3.load("img3.jpg");
         
         var img4:PreLoader = new PreLoader();
         img4.loadImmediately("img4.jpg");
         
         // now the queue looks like this:
         // img4.jpg, img1.jpg, img2.jpg, img3.jpg
         // where img4.jpg is currently loading
         

Parameters

urlStringOrURLRequest:* — url as String ("image.png") or URLRequest.

See also

loadNext()method 
public function loadNext(urlStringOrURLRequest:*):void

loads the passed url (or URLRequest) by adding it after the current loading request.

This call will be ignored when its currently loading.

Example:

         var img1:PreLoader = new PreLoader();
         img1.load("img1.jpg");
         
         var img2:PreLoader = new PreLoader();
         img2.load("img2.jpg");
         
         var img3:PreLoader = new PreLoader();
         img3.load("img3.jpg");
         
         var img4:PreLoader = new PreLoader();
         img4.loadNext("img4.jpg");
         
         // now the queue looks like this:
         // img1.jpg, img4.jpg, img2.jpg, img3.jpg
         // where img1.jpg is currently loading
         

Parameters

urlStringOrURLRequest:* — url as String ("image.png") or URLRequest.

See also

toString()method 
override public function toString():String

returns [PreLoader] thePassedUrl (i.e. [PreLoader] http://www.domain.com/image1.png).

Returns
String
unload()method 
public function unload():void

unloads the loader.

See also

flash.display.Loader.unload()