Packagenet.guttershark.control
Classpublic final class PreloadController
InheritancePreloadController Inheritance flash.events.EventDispatcher

The PreloadController 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 AssetManager.


Example
Using the preload controller:
  
  import net.guttershark.control.PreloadController;
  import net.guttershark.managers.AssetManager;
  import net.guttershark.managers.EventManager;
  import net.guttershark.support.preloading.Asset;
  
  public class PreloaderTest extends DocumentController 
  {
     
     public var preloader:MovieClip;
     
     public function PreloaderTest()
     {
         super();
     }
     
     private function setupComplete():void
     {
         pc = new PreloadController(400);
         var assets:Array = [
            new Asset("assets/jpg1.jpg","jpg1"),
            new Asset("assets/jpg2.jpg","jpg2"), 
            new Asset("assets/png1.png","png1"),
            new Asset("assets/png2.png","png2"),
            new Asset("swfload_test.swf","swf1"),
            new Asset("assets/sound1.mp3","snd1"),
            new Asset("assets/Pizza_Song.flv","pizza")
        ];
        pc.addItems(assets);
        em.handleEvents(pc,this,"onPC",true);
        pc.prioritize(assets[4]); //prioritize the swf.
        pc.start(); //start it;
        pc.stop(); //pause it
        setTimeout(pc.start,4000); //resume it
     }
     
     private function onPCProgress(pe:PreloadProgressEvent):void
     {
         trace(pe.toString());
         preloader.width = pe.pixels
     }
     
     private function onPCAssetComplete(e:AssetCompleteEvent):void
     {
         trace(e.toString());
     }
     
     private function onPCComplete(e:Event):void
     {
         addChild(am.getMovieClipFromSWFLibrary("swf1", "Test"));
         addChild(am.getBitmap("jpg1"));
     }
  }
  



Public Properties
 PropertyDefined by
  lastCompletedAsset : Asset
[read-only] The last completed asset.
PreloadController
  numLeft : int
[read-only] The number of items left in the preload queue.
PreloadController
  pixelsToFill : int
[write-only] Set the number of pixels to fill, useful if the pixel calculations need to change.
PreloadController
  working : Boolean
[read-only] Indicates whether or not this controller is doing any preloading.
PreloadController
Public Methods
 MethodDefined by
  
PreloadController(pixelsToFill:int = 100)
Constructor for PreloadController instances.
PreloadController
  
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.
PreloadController
  
addPrioritizedItems(items:Array):void
Add items to the controller to load, with top priority.
PreloadController
  
dispose():void
Dispose of this preloadController.
PreloadController
  
prioritize(asset:Asset):void
Prioritize an asset.
PreloadController
  
reset():void
Resets internal state.
PreloadController
  
start():void
Starts loading the assets, and resumes loading from a stopped state.
PreloadController
  
stop():void
Stops this preload controller from loading assets, if there is an asset currently loading, that asset will finish loading, but the controller will not continue after that.
PreloadController
Events
 EventSummaryDefined by
   Dispatched for each asset that has completed downloading.PreloadController
   Dispatched for each asset that has has stopped downloading because of an error.PreloadController
   Dispatched for each asset that has started downloading.PreloadController
   Dispatched for each asset that is downloading.PreloadController
   Dispatched for each asset that generated an http status code other than 0 or 200.PreloadController
   Dispatched when the preload controller completes downloading all assets in the queue.PreloadController
   Dispatched on progress of the entire PreloadController progress.PreloadController
Property detail
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
pixelsToFillproperty 
pixelsToFill:int  [write-only]

Set the number of pixels to fill, useful if the pixel calculations need to change.

Implementation
    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
PreloadController()constructor
public function PreloadController(pixelsToFill:int = 100)

Constructor for PreloadController instances.

Parameters
pixelsToFill:int (default = 100) — pixelsToFill The total number of pixels this preloader needs to fill - this is used in calculating both pixels and percent.

See also

PreloadProgressEvent event
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.

See also

Asset class
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.

See also

Asset class
dispose()method 
public function dispose():void

Dispose of this preloadController.

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

Prioritize an asset.

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

Resets internal state.

start()method 
public function start():void

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

See also

stop()method 
public function stop():void

Stops this preload controller from loading assets, if there is an asset currently loading, that asset will finish loading, but the controller will not continue after that.

See also

Event detail
assetCompleteevent 
Event object type: net.guttershark.support.preloading.events.AssetCompleteEvent

Dispatched for each asset that has completed downloading.

assetErrorevent  
Event object type: net.guttershark.support.preloading.events.AssetErrorEvent

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

assetOpenevent  
Event object type: net.guttershark.support.preloading.events.AssetOpenEvent

Dispatched for each asset that has started downloading.

assetProgressevent  
Event object type: net.guttershark.support.preloading.events.AssetProgressEvent

Dispatched for each asset that is downloading.

assetStatusevent  
Event object type: net.guttershark.support.preloading.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 preload controller completes downloading all assets in the queue.

preloadProgressevent  
Event object type: net.guttershark.support.preloading.events.PreloadProgressEvent

Dispatched on progress of the entire PreloadController progress.