Packagegs.preloading.workers
Classpublic class Worker
InheritanceWorker Inheritance flash.events.EventDispatcher
SubclassesBitmapWorker, FLVWorker, FZipWorker, JSONWorker, SoundWorker, StyleSheetWorker, SWFWorker, TextWorker, XMLWorker

The Worker class is a generic worker that implements base logic for loading an Asset. Most subclasses don't need to override all of the logic in this class.

The worker provides default behavior like listening to events from the internal loader and taking care of the callbacks, and routing the events to the associated Preloader.

This worker class cannot be used directly, it must be subclassed. You must override the "load" method and implement your own logic to prepare the internal loader and request objects.

Worker subclasses must also be registered by calling Worker.RegisterDefaultWorkers and Worker.RegisterWorkerForFileType.

Here's a snippet taken from the BitmapWorker class that shows overriding the load method and setting up the internal loader and request properties.


Example
Overriding the load method
 
  override public function load(asset:Asset):void
  {
     this.asset = asset;
     request = new URLRequest(asset.source);
     loader = new Loader();
     loader.contentLoaderInfo.addEventListener(Event.OPEN, super.onOpen);
     loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, super.onProgress);
     loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHTTPStatus);
     loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, super.onIOLoadError);
     loader.contentLoaderInfo.addEventListener(IOErrorEvent.DISK_ERROR, super.onIOLoadError);
     loader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, super.onIOLoadError);
     loader.contentLoaderInfo.addEventListener(IOErrorEvent.VERIFY_ERROR, super.onIOLoadError);
     loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityError);
     loader.contentLoaderInfo.addEventListener(Event.COMPLETE, super.onComplete);
     start(); //kicks off the loading, default loading logic is in the Worker class.
  }
  

See the source code in any other worker in this package for subclassing examples.

See also

gs.preloading.Preloader
gs.managers.AssetManager


Public Properties
 PropertyDefined by
  loaderContext : LoaderContext
The loader context for the asset being loaded.
Worker
Protected Properties
 PropertyDefined by
  asset : Asset
The asset this worker is loading.
Worker
  loader : *
Internal loader used for loading the asset.
Worker
  request : URLRequest
The URLRequest for the asset.
Worker
Public Methods
 MethodDefined by
  
close():void
Close the internal loader.
Worker
  
dispose():void
Dispose of this worker instance.
Worker
  
GetWorkerInstance(fileType:String):Worker
[static] Get an instance of the worker specified by type.
Worker
  
load(asset:Asset):void
Load an asset.
Worker
  
[static] Registers the default worker instances internally.
Worker
  
RegisterWorkerForFileType(fileType:String, workerKlass:Class):void
[static] Registers a worker for a file type.
Worker
  
start():void
Starts loading the internal loader instance.
Worker
Protected Methods
 MethodDefined by
  
onComplete(e:Event):void
The event handler for the internal loaders complete event.
Worker
  
onHTTPStatus(hse:HTTPStatusEvent):void
The event handler for the internal loaders http status event.
Worker
  
onIOLoadError(e:IOErrorEvent):void
The event handler for the internal loaders error event.
Worker
  
onOpen(e:Event):void
The event handler for the internal loaders open event.
Worker
  
onProgress(pe:ProgressEvent):void
The event handler for the internal loaders progress.
Worker
  
onSecurityError(se:SecurityErrorEvent):void
The event handler for the internal loaders security error event.
Worker
Events
 EventSummaryDefined by
   Dispatched when the worker has completed downloading the asset.Worker
   Dispatched when there is an error loading an asset.Worker
   Dispatched when the loader starts loading the asset.Worker
   Dispatched on progress from the loader that is loading the asset.Worker
   Dispatched when an HTTPStatus event occurs from the internal loader.Worker
   Dispatched when a security error happens while attempting to load the item.Worker
Property detail
assetproperty
protected var asset:Asset

The asset this worker is loading.

loaderproperty 
protected var loader:*

Internal loader used for loading the asset.

This is untyped so that any type of loader can be used. The loader you use must have a "load" method declared on it that accepts a URLRequest.

loaderContextproperty 
public var loaderContext:LoaderContext

The loader context for the asset being loaded.

requestproperty 
protected var request:URLRequest

The URLRequest for the asset.

Method detail
close()method
public function close():void

Close the internal loader.

dispose()method 
public function dispose():void

Dispose of this worker instance.

GetWorkerInstance()method 
public static function GetWorkerInstance(fileType:String):Worker

Get an instance of the worker specified by type.

Parameters
fileType:String — The type of the worker. EX: 'bitmap', or 'swf', etc. The Worker must have been registered previously before getting an instnace of it.

Returns
Worker
load()method 
public function load(asset:Asset):void

Load an asset.

This will throw an exception if you do not override the method.

Parameters
asset:Asset — the asset to load.
onComplete()method 
protected function onComplete(e:Event):void

The event handler for the internal loaders complete event.

Parameters
e:Event — The event from the internal loaders complete event.
onHTTPStatus()method 
protected function onHTTPStatus(hse:HTTPStatusEvent):void

The event handler for the internal loaders http status event.

Parameters
hse:HTTPStatusEvent — The status event from the internal loader.
onIOLoadError()method 
protected function onIOLoadError(e:IOErrorEvent):void

The event handler for the internal loaders error event.

Parameters
e:IOErrorEvent — The error event from the internal loader.
onOpen()method 
protected function onOpen(e:Event):void

The event handler for the internal loaders open event.

Parameters
e:Event — The open event from the internal loader.
onProgress()method 
protected function onProgress(pe:ProgressEvent):void

The event handler for the internal loaders progress.

Parameters
pe:ProgressEvent — The progress event from the internal loader.
onSecurityError()method 
protected function onSecurityError(se:SecurityErrorEvent):void

The event handler for the internal loaders security error event.

Parameters
se:SecurityErrorEvent — The security error event from the internal loader.
RegisterDefaultWorkers()method 
public static function RegisterDefaultWorkers():void

Registers the default worker instances internally. The default types are:

RegisterWorkerForFileType()method 
public static function RegisterWorkerForFileType(fileType:String, workerKlass:Class):void

Registers a worker for a file type. The file type string should be a file extension less the period. EX: "jpg","jpeg", etc.

Parameters
fileType:String — The file type to register the worker too
 
workerKlass:Class — The worker class to use for the specified file type. This must be a class reference.
start()method 
public function start():void

Starts loading the internal loader instance.

The loader you set for the internal loader must have a "load" method defined and accept a URLRequest

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

Dispatched when the worker has completed downloading the asset.

assetErrorevent  
Event object type: gs.events.AssetErrorEvent

Dispatched when there is an error loading an asset.

assetOpenevent  
Event object type: gs.events.AssetOpenEvent

Dispatched when the loader starts loading the asset.

assetProgressevent  
Event object type: gs.events.AssetProgressEvent

Dispatched on progress from the loader that is loading the asset.

assetStatusevent  
Event object type: gs.events.AssetStatusEvent

Dispatched when an HTTPStatus event occurs from the internal loader. This only dispatches for HTTP status codes other than 0 and 200.

securityErrorevent  
Event object type: flash.events.SecurityErrorEvent

Dispatched when a security error happens while attempting to load the item.