Package | com.whirled |
Class | public class DataPack |
Inheritance | DataPack ![]() ![]() |
Method | Defined by | ||
---|---|---|---|
DataPack(source:Object, completeListener:Function = null, errorListener:Function = null)
Construct a DataPack to be loaded from the specified source.
| DataPack | ||
close():void
If the DataPack is still loading, stop it, otherwise has no effect.
| DataPack | ||
![]() |
getArray(name:String):Array
Convenience function to access some data as an Array.
| BaseDataPack | |
![]() |
getBoolean(name:String):Boolean
Convenience function to access some data as a Boolean.
| BaseDataPack | |
![]() |
getColor(name:String):uint
Convenience function to access some data as a color (uint).
| BaseDataPack | |
![]() |
getData(name:String, formatType:String = null):*
Get some data, optionally formatted as a different type than that specified in the data xml.
| BaseDataPack | |
getDisplayObjects(sources:Object, callback:Function, appDom:ApplicationDomain = null):void
Get some display objects in the datapack.
| DataPack | ||
![]() |
getFile(name:String):ByteArray
Get a File, as a ByteArray.
| BaseDataPack | |
![]() |
getFileAsString(name:String):String
Get a File, as a String.
| BaseDataPack | |
![]() |
getFileAsXML(name:String):XML
Get a File, as an XML object.
| BaseDataPack | |
![]() |
getInt(name:String):int
Convenience function to access some data as an int.
| BaseDataPack | |
getLoaders(sources:Object, callback:Function, appDom:ApplicationDomain = null):void
Get Loaders containing the specified files from the datapack.
| DataPack | ||
![]() |
getNumber(name:String):Number
Convenience function to access some data as a Number.
| BaseDataPack | |
![]() |
getPoint(name:String):Point
Convenience function to access some data as a Point.
| BaseDataPack | |
![]() |
getRectangle(name:String):Rectangle
Convenience function to access some data as a Rectangle.
| BaseDataPack | |
![]() |
getString(name:String):String
Convenience function to access some data as a String.
| BaseDataPack | |
![]() |
isComplete():Boolean
Has the loading of the datapack completed?
| BaseDataPack | |
load(sources:Object, completeListener:Function):void
[static]
A static helper method to load one or more DataPacks without using any event listeners.
| DataPack |
Method | Defined by | ||
---|---|---|---|
bytesAvailable(bytes:ByteArray):void
Read the zip file.
| DataPack | ||
![]() |
extractStringValue(datum:XML, valueField:String = "value"):*
Extract from the datum either a String, null, or undefined.
| BaseDataPack | |
![]() |
getDatum(list:XMLList, name:String):XML
Fucking hell.
| BaseDataPack | |
![]() |
parseValueFromString(string:String, type:String):Object
| BaseDataPack |
Event | Summary | Defined by | ||
---|---|---|---|---|
Dispatched when the DataPack has completed loading. | DataPack | |||
![]() | Dispatched when the DataPack could not load due to an error. | BaseDataPack |
DataPack | () | constructor |
public function DataPack(source:Object, completeListener:Function = null, errorListener:Function = null)
Construct a DataPack to be loaded from the specified source. Note that passing a ByteArray will result in a DataPack that is instantly complete.
Parameterssource:Object — a url (as a String or as a URLRequest) from which to load the
DataPack, or a ByteArray containing the raw data, or a Class.
|
|
completeListener:Function (default = null ) — a listener function to automatically register for COMPLETE events.
|
|
errorListener:Function (default = null ) — a listener function to automatically register for ERROR events.
|
— if urlOrByteArray is not of the right type.
|
bytesAvailable | () | method |
protected override function bytesAvailable(bytes:ByteArray):void
Read the zip file.
Parametersbytes:ByteArray |
close | () | method |
public function close():void
If the DataPack is still loading, stop it, otherwise has no effect. It would be a good idea to call this during your UNLOAD handling.
getDisplayObjects | () | method |
public function getDisplayObjects(sources:Object, callback:Function, appDom:ApplicationDomain = null):void
Get some display objects in the datapack. Note: With the move to flash 10, it's now illegal to "reparent" a SWF that was compiled with AVM1 (flash 8, or newer but compiled as actionscript 1/2). It will work fine in flashplayer 9, but in flashplayer 10 it will give a runtime error. The workaround is to use getLoaders() instead, and add the Loader to your hierarchy.
Parameterssources:Object — an Object containing keys mapping to the names of the display objects to load.
|
|
callback:Function — a Function that will be called when all the display objects
are loaded (or were unable to load).
Signature: function (results :Object) :void
results will contain a mapping from name -> DisplayObject, or null if none.
|
|
appDom:ApplicationDomain (default = null ) — The ApplicationDomain in which to load the DisplayObjects. The default value
of null will load into a child of the current ApplicationDomain.
|
getLoaders | () | method |
public function getLoaders(sources:Object, callback:Function, appDom:ApplicationDomain = null):void
Get Loaders containing the specified files from the datapack. These Loaders will hold the DisplayObject or Image files, and can be safely added to your display hierarchy without causing any errors, even if loading an AVM1 swf.
Parameterssources:Object — an Object containing keys mapping to the names of the display objects to load.
|
|
callback:Function — a Function that will be called when all the display objects
are loaded (or were unable to load).
Signature: function (results :Object) :void .
results will contain a mapping from name -> Loader, or null.
|
|
appDom:ApplicationDomain (default = null ) — The ApplicationDomain in which to load the DisplayObjects. The default value
of null will load into a child of the current ApplicationDomain.
|
load | () | method |
public static function load(sources:Object, completeListener:Function):void
A static helper method to load one or more DataPacks without using any event listeners. Take a deep breath and then read the parameter documentation.
Parameterssources:Object — can be a String (representing a URL), or a URLRequest object, or a
ByteArray containing an embedded DataPack, or a Class object that will instantiate
with no args into a ByteArray or (unlikely) a URLRequest. Orrrrrr, sources can be
an Array, Dictionary or plain Object containing primary kinds of sources as the values.
|
|
completeListener:Function — a function with the signature:
function (result :Object) :void;
If you passed in only a single source, then this completeListener is called and provided
with a result of either a DataPack (for a successful load) or an Error object.
If it's an Error but your function only accepts a DataPack, an error message will be
calmly logged. If your sources was an Array, Dictionary, or Object then the result will
be an object of the same type, with the same keys, but with each value being either a
DataPack or an Error.
|
function gotDataPack (result :Object) :void { if (!(result is DataPack)) { // result must be an Error trace("Why? Oh why!? .. Oh: " + result); return; } var pack :DataPack = (result as DataPack); // _weapon is something set up outside the scope of this example _weapon.name = pack.getString("name"); _weapon.astonishmentPoints = pack.getNumber("ap"); // etc. } // ok, the function is set up, let's load the DataPack var itemInfos :Array = _gameCtrl.getItemPacks(); for each (var itemInfo :Object in itemInfos) { if (itemInfo.ident == "bubblePopper") { DataPack.load(itemInfo.mediaURL, gotDataPack); break; } }
complete | event |