Packagecom.pblabs.engine.resource
Classpublic class Resource
InheritanceResource Inheritance flash.events.EventDispatcher
Subclasses DataResource, ImageResource, SoundResource, SWFResource, XMLResource

A resource contains data for a specific type of game asset. This base class does not define what that type is, so subclasses should be created and used for each different type of asset.

The Resource class and any subclasses should never be instantiated directly. Instead, use the ResourceManager class.

Usually, resources are created by loading data from a file, but this is not necessarily a requirement

See also

ResourceManager


Public Properties
 PropertyDefined By
  didFail : Boolean
[read-only] Whether or not the resource failed to load.
Resource
  filename : String
The filename the resource data was loaded from.
Resource
  isLoaded : Boolean
[read-only] Whether or not the resource has been loaded.
Resource
  referenceCount : int
[read-only] The number of places this resource is currently referenced from.
Resource
Protected Properties
 PropertyDefined By
  _filename : String = null
Resource
  resourceLoader : Loader
[read-only] The Loader object that was used to load this resource.
Resource
Public Methods
 MethodDefined By
  
Decrements the number of references to the resource.
Resource
  
dispose():void
Disposes resource and cleans data
Resource
  
fail(message:String):void
This method will be used by a Resource Provider to indicate that this resource has failed loading
Resource
  
Increments the number of references to the resource.
Resource
  
initialize(data:*):void
initializes the resource with data from a byte array.
Resource
  
load(filename:String):void
Loads resource data from a file.
Resource
Protected Methods
 MethodDefined By
  
onContentReady(content:*):Boolean
This is called when the resource data has been fully loaded and conditioned.
Resource
  
onFailed(message:String):void
Resource
  
onLoadComplete(event:Event = null):void
Called when loading and conditioning of the resource data is complete.
Resource
Events
 Event Summary Defined By
   This event is dispatched by a resource when loading of the resource's data fails.Resource
   This event is dispatched by a resource upon successful load of the resource's data.Resource
Property Detail
_filenameproperty
protected var _filename:String = null

didFailproperty 
didFail:Boolean  [read-only]

Whether or not the resource failed to load. This is only valid after the resource has loaded, so being false only verifies a successful load if IsLoaded is true.


Implementation
    public function get didFail():Boolean

See also

filenameproperty 
filename:String

The filename the resource data was loaded from.


Implementation
    public function get filename():String
    public function set filename(value:String):void
isLoadedproperty 
isLoaded:Boolean  [read-only]

Whether or not the resource has been loaded. This only marks whether loading has been completed, not whether it succeeded. If this is true, DidFail can be checked to see if loading was successful.


Implementation
    public function get isLoaded():Boolean

See also

referenceCountproperty 
referenceCount:int  [read-only]

The number of places this resource is currently referenced from. When this reaches zero, the resource will be unloaded.


Implementation
    public function get referenceCount():int
resourceLoaderproperty 
resourceLoader:Loader  [read-only]

The Loader object that was used to load this resource. This is set to null after onContentReady returns true.


Implementation
    protected function get resourceLoader():Loader
Method Detail
decrementReferenceCount()method
public function decrementReferenceCount():void

Decrements the number of references to the resource. This should only ever be called by the ResourceManager.

dispose()method 
public function dispose():void

Disposes resource and cleans data

fail()method 
public function fail(message:String):void

This method will be used by a Resource Provider to indicate that this resource has failed loading

Parameters

message:String

incrementReferenceCount()method 
public function incrementReferenceCount():void

Increments the number of references to the resource. This should only ever be called by the ResourceManager.

initialize()method 
public function initialize(data:*):void

initializes the resource with data from a byte array. This implementation loads the data with a content loader. If that behavior is not needed (XML doesn't need this, for example), this method can be overridden. Subclasses that do override this method must call onLoadComplete when they have finished loading and conditioning the byte array.

Parameters

data:* — The data to initialize the resource with.

load()method 
public function load(filename:String):void

Loads resource data from a file.

Parameters

filename:String — The filename or url to load data from. A ResourceEvent will be dispatched when the load completes - LOADED_EVENT on successful load, or FAILED_EVENT if the load fails.

onContentReady()method 
protected function onContentReady(content:*):Boolean

This is called when the resource data has been fully loaded and conditioned. Returning true from this method means the load was successful. False indicates failure. Subclasses must implement this method.

Parameters

content:* — The fully conditioned data for this resource.

Returns
Boolean — True if content contains valid data, false otherwise.
onFailed()method 
protected function onFailed(message:String):void

Parameters

message:String

onLoadComplete()method 
protected function onLoadComplete(event:Event = null):void

Called when loading and conditioning of the resource data is complete. This must be called by, and only by, subclasses that override the initialize method.

Parameters

event:Event (default = null) — This can be ignored by subclasses.

Event Detail
FAILED_EVENT Event
Event Object Type: com.pblabs.engine.resource.ResourceEvent
ResourceEvent.type property = com.pblabs.engine.resource.ResourceEvent.FAILED_EVENT

This event is dispatched by a resource when loading of the resource's data fails.
LOADED_EVENT Event  
Event Object Type: com.pblabs.engine.resource.ResourceEvent
ResourceEvent.type property = com.pblabs.engine.resource.ResourceEvent.LOADED_EVENT

This event is dispatched by a resource upon successful load of the resource's data.