Packagecom.whirled
Classpublic class DataPack
InheritanceDataPack Inheritance BaseDataPack Inheritance flash.events.EventDispatcher

A DataPack is a bundle of stored goodies for use by your game, avatar, or other whirled creation. In a DataPack can be named data values as well as named files.



Public Methods
 MethodDefined 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
 Inherited
getArray(name:String):Array
Convenience function to access some data as an Array.
BaseDataPack
 Inherited
getBoolean(name:String):Boolean
Convenience function to access some data as a Boolean.
BaseDataPack
 Inherited
getColor(name:String):uint
Convenience function to access some data as a color (uint).
BaseDataPack
 Inherited
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
 Inherited
getFile(name:String):ByteArray
Get a File, as a ByteArray.
BaseDataPack
 Inherited
getFileAsString(name:String):String
Get a File, as a String.
BaseDataPack
 Inherited
getFileAsXML(name:String):XML
Get a File, as an XML object.
BaseDataPack
 Inherited
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
 Inherited
getNumber(name:String):Number
Convenience function to access some data as a Number.
BaseDataPack
 Inherited
getPoint(name:String):Point
Convenience function to access some data as a Point.
BaseDataPack
 Inherited
getRectangle(name:String):Rectangle
Convenience function to access some data as a Rectangle.
BaseDataPack
 Inherited
getString(name:String):String
Convenience function to access some data as a String.
BaseDataPack
 Inherited
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
Protected Methods
 MethodDefined by
  
bytesAvailable(bytes:ByteArray):void
Read the zip file.
DataPack
 Inherited
extractStringValue(datum:XML, valueField:String = "value"):*
Extract from the datum either a String, null, or undefined.
BaseDataPack
 Inherited
getDatum(list:XMLList, name:String):XML
Fucking hell.
BaseDataPack
 Inherited
parseValueFromString(string:String, type:String):Object
BaseDataPack
Events
 EventSummaryDefined by
   Dispatched when the DataPack has completed loading.DataPack
 Inherited Dispatched when the DataPack could not load due to an error.BaseDataPack
Constructor detail
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.

Parameters
source: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.

Throws
— if urlOrByteArray is not of the right type.
Method detail
bytesAvailable()method
protected override function bytesAvailable(bytes:ByteArray):void

Read the zip file.

Parameters
bytes: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.

Parameters
sources: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.

Parameters
sources: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.

Parameters
sources: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.

Example
Load one DataPack from a url.
     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;
         }
     }
     

Event detail
completeevent 
Event object type: flash.events.Event

Dispatched when the DataPack has completed loading.