| Package | gs.preloading.workers |
| Class | public class Worker |
| Inheritance | Worker flash.events.EventDispatcher |
| Subclasses | BitmapWorker, FLVWorker, FZipWorker, JSONWorker, SoundWorker, StyleSheetWorker, SWFWorker, TextWorker, XMLWorker |
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.
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
| Property | Defined by | ||
|---|---|---|---|
| loaderContext : LoaderContext
The loader context for the asset being loaded.
| Worker | ||
| Property | Defined 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 | ||
| Method | Defined 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 an asset.
| Worker | ||
|
RegisterDefaultWorkers():void
[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 | ||
| Method | Defined 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 | ||
| Event | Summary | Defined 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 | |||
| asset | property |
protected var asset:AssetThe asset this worker is loading.
| loader | property |
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.
| loaderContext | property |
public var loaderContext:LoaderContextThe loader context for the asset being loaded.
| request | property |
protected var request:URLRequestThe URLRequest for the asset.
| close | () | method |
public function close():voidClose the internal loader.
| dispose | () | method |
public function dispose():voidDispose of this worker instance.
| GetWorkerInstance | () | method |
public static function GetWorkerInstance(fileType:String):WorkerGet an instance of the worker specified by type.
ParametersfileType:String — The type of the worker. EX: 'bitmap', or 'swf', etc. The Worker must
have been registered previously before getting an instnace of it.
|
Worker |
| load | () | method |
public function load(asset:Asset):voidLoad an asset.
This will throw an exception if you do not override the method.
Parametersasset:Asset — the asset to load.
|
| onComplete | () | method |
protected function onComplete(e:Event):voidThe event handler for the internal loaders complete event.
Parameterse:Event — The event from the internal loaders complete event.
|
| onHTTPStatus | () | method |
protected function onHTTPStatus(hse:HTTPStatusEvent):voidThe event handler for the internal loaders http status event.
Parametershse:HTTPStatusEvent — The status event from the internal loader.
|
| onIOLoadError | () | method |
protected function onIOLoadError(e:IOErrorEvent):voidThe event handler for the internal loaders error event.
Parameterse:IOErrorEvent — The error event from the internal loader.
|
| onOpen | () | method |
protected function onOpen(e:Event):voidThe event handler for the internal loaders open event.
Parameterse:Event — The open event from the internal loader.
|
| onProgress | () | method |
protected function onProgress(pe:ProgressEvent):voidThe event handler for the internal loaders progress.
Parameterspe:ProgressEvent — The progress event from the internal loader.
|
| onSecurityError | () | method |
protected function onSecurityError(se:SecurityErrorEvent):voidThe event handler for the internal loaders security error event.
Parametersse:SecurityErrorEvent — The security error event from the internal loader.
|
| RegisterDefaultWorkers | () | method |
public static function RegisterDefaultWorkers():voidRegisters the default worker instances internally. The default types are:
| RegisterWorkerForFileType | () | method |
public static function RegisterWorkerForFileType(fileType:String, workerKlass:Class):voidRegisters a worker for a file type. The file type string should be a file extension less the period. EX: "jpg","jpeg", etc.
ParametersfileType: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():voidStarts loading the internal loader instance.
The loader you set for the internal loader must have a "load" method defined and accept a URLRequest
| assetComplete | event |
gs.events.AssetCompleteEvent
Dispatched when the worker has completed downloading the asset.
| assetError | event |
| assetOpen | event |
| assetProgress | event |
gs.events.AssetProgressEvent
Dispatched on progress from the loader that is loading the asset.
| assetStatus | event |
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.
| securityError | event |
flash.events.SecurityErrorEvent
Dispatched when a security error happens while attempting to load the item.