| Package | com.apdevblog.load |
| Class | public class PreLoader |
| Inheritance | PreLoader flash.display.Sprite |
| Runtime Versions : | AIR 1.0, Flash Player 9 |
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
| Property | Defined 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 | ||
| Method | Defined 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 | ||
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 | ||
| autoUnload | property |
autoUnload:Boolean [read-write] If true, unload is called, when the PreLoader is removed from stage (to prepare the Loader for garbage collection).
public function get autoUnload():Boolean public function set autoUnload(value:Boolean):void| content | property |
content:DisplayObject [read-only] returns the content DisplayObject of the containt loader.
public function get content():DisplayObjectSee also
| contentLoaderInfo | property |
contentLoaderInfo:LoaderInfo [read-only] returns the LoaderInfo
Similar to Loader.contentLoaderInfo.
public function get contentLoaderInfo():LoaderInfoSee also
| isImage | property |
isImage:Boolean [read-only] returns whether the PreLoader loads an image
public function get isImage():Boolean| isInit | property |
isInit:Boolean [read-only] returns if is init.
Is set to true, when onLoadInit is received.
public function get isInit():Boolean| isLoaded | property |
isLoaded:Boolean [read-only] returns if the loading is complete.
public function get isLoaded():Boolean| loader | property |
loader:Loader [read-only] returns the Loader.
public function get loader():Loader| loaderContext | property |
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.
public function get loaderContext():LoaderContext public function set loaderContext(value:LoaderContext):void| scale | property |
scale:Number [write-only] sets scaleX and scaleY in one go
public function set scale(value:Number):void| smooth | property |
smooth:Boolean [read-write] gets and sets whether the PreLoaded should be smoothed when scaled (this applies only when loading image).
public function get smooth():Boolean public function set smooth(value:Boolean):void| url | property |
url:String [read-only] returns the url (if passed already).
public function get url():String| urlRequest | property |
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.
public function get urlRequest():URLRequest| PreLoader | () | Constructor |
public function PreLoader()Constructor
| closeLoad | () | method |
public function closeLoad():voidstops 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:PreLoader — PreLoader 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():Stringreturns [PreLoader] thePassedUrl (i.e. [PreLoader] http://www.domain.com/image1.png).
ReturnsString |
| unload | () | method |
public function unload():voidunloads the loader.
See also