Packagegs.preloading
Classpublic final class Preloader
InheritancePreloader Inheritance flash.events.EventDispatcher

The Preloader class is a controller you use for loading assets.

It provides you with methods for starting, stopping, pausing, resuming and prioritizing of assets, and registers all loaded assets with the asset manager.

By default, the Preloader loads all swf's and bitmap's into the same application domain. Unless specified otherwise in the constructor.

Examples are in the guttershark repository.

See also

gs.managers.AssetManager


Public Properties
 PropertyDefined by
  kbps : Number
[read-only] Kilobytes per second of the currently loading asset.
Preloader
  lastCompletedAsset : Asset
[read-only] The last completed asset.
Preloader
  numLeft : int
[read-only] The number of items left in the preload queue.
Preloader
  percentLoaded : Number
[read-only]
Preloader
  pixelsFull : Number
Returns the pixels full, based off of how much has downloaded, and how many pixelsToFill.
Preloader
  pixelsToFill : int
The number of pixels that should be filled.
Preloader
  working : Boolean
[read-only] Indicates whether or not this controller is doing any preloading.
Preloader
Public Methods
 MethodDefined by
  
Preloader(pixelsToFill:int = 100, loaderContext:LoaderContext = null)
Constructor for Preloader instances.
Preloader
  
addItems(items:Array):void
Add items to the controller to load - if the preloader is currently working, these items will be appended to the items to load.
Preloader
  
addPrioritizedItems(items:Array):void
Add items to the controller to load, with top priority.
Preloader
  
dispose():void
Dispose of this preloader.
Preloader
  
pause():void
Pause the preloader.
Preloader
  
prioritize(asset:Asset):void
Prioritize an asset.
Preloader
  
reset():void
Resets internal state so the Preloader can be re-used if needed.
Preloader
  
start():void
Starts loading the assets, and resumes loading from a stopped state.
Preloader
  
stop():void
Stops the preloader and closes the current loading assets.
Preloader
Events
 EventSummaryDefined by
   Dispatched for each asset that has completed downloading.Preloader
   Dispatched for each asset that has has stopped downloading because of an error.Preloader
   Dispatched for each asset that has started downloading.Preloader
   Dispatched for each asset that is downloading.Preloader
   Dispatched for each asset that generated an http status code other than 0 or 200.Preloader
   Dispatched when the Preloader completes downloading all assets in the queue.Preloader
   Dispatched on progress of the entire Preloader progress.Preloader
Property detail
kbpsproperty
kbps:Number  [read-only]

Kilobytes per second of the currently loading asset.

Implementation
    public function get kbps():Number
lastCompletedAssetproperty 
lastCompletedAsset:Asset  [read-only]

The last completed asset.

Implementation
    public function get lastCompletedAsset():Asset
numLeftproperty 
numLeft:int  [read-only]

The number of items left in the preload queue.

Implementation
    public function get numLeft():int
percentLoadedproperty 
percentLoaded:Number  [read-only]Implementation
    public function get percentLoaded():Number
pixelsFullproperty 
pixelsFull:Number  [read-write]

Returns the pixels full, based off of how much has downloaded, and how many pixelsToFill. For example - if the pixels to fill is 100, and 10% of the download is complete, this will return 10.

Implementation
    public function get pixelsFull():Number
    public function set pixelsFull(value:Number):void
pixelsToFillproperty 
pixelsToFill:int  [read-write]

The number of pixels that should be filled.

Implementation
    public function get pixelsToFill():int
    public function set pixelsToFill(value:int):void
workingproperty 
working:Boolean  [read-only]

Indicates whether or not this controller is doing any preloading.

Implementation
    public function get working():Boolean
Constructor detail
Preloader()constructor
public function Preloader(pixelsToFill:int = 100, loaderContext:LoaderContext = null)

Constructor for Preloader instances.

Parameters
pixelsToFill:int (default = 100) — The total number of pixels this preloader needs to fill - this is used in calculating both pixels and percent.
 
loaderContext:LoaderContext (default = null) — The loader context for all assets being loaded with this Preloader.
Method detail
addItems()method
public function addItems(items:Array):void

Add items to the controller to load - if the preloader is currently working, these items will be appended to the items to load.

Parameters
items:Array — An array of Asset instances.
addPrioritizedItems()method 
public function addPrioritizedItems(items:Array):void

Add items to the controller to load, with top priority.

Parameters
items:Array — An array of Asset instances.
dispose()method 
public function dispose():void

Dispose of this preloader.

pause()method 
public function pause():void

Pause the preloader.

The current item will finish loading but not continue until you start it again.

prioritize()method 
public function prioritize(asset:Asset):void

Prioritize an asset.

Parameters
asset:Asset — An asset instance that's in the queue to be loaded.
reset()method 
public function reset():void

Resets internal state so the Preloader can be re-used if needed.

start()method 
public function start():void

Starts loading the assets, and resumes loading from a stopped state.

stop()method 
public function stop():void

Stops the preloader and closes the current loading assets.

Event detail
assetCompleteevent 
Event object type: gs.events.AssetCompleteEvent

Dispatched for each asset that has completed downloading.

assetErrorevent  
Event object type: gs.events.AssetErrorEvent

Dispatched for each asset that has has stopped downloading because of an error.

assetOpenevent  
Event object type: gs.events.AssetOpenEvent

Dispatched for each asset that has started downloading.

assetProgressevent  
Event object type: gs.support.preloading.events.AssetProgressEvent

Dispatched for each asset that is downloading.

assetStatusevent  
Event object type: gs.events.AssetStatusEvent

Dispatched for each asset that generated an http status code other than 0 or 200.

completeevent  
Event object type: flash.events.Event

Dispatched when the Preloader completes downloading all assets in the queue.

preloadProgressevent  
Event object type: gs.events.PreloadProgressEvent

Dispatched on progress of the entire Preloader progress.