Packageflash.net
Classpublic final class URLLoaderDataFormat
InheritanceURLLoaderDataFormat Inheritance Object

Language version: ActionScript 3.0
Runtime version: 

The URLLoaderDataFormat class provides values that specify how downloaded data is received.

View the examples.



Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined by
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Public Constants
 ConstantDefined by
  BINARY : String = "binary"
[static] Specifies that downloaded data is received as raw binary data.
URLLoaderDataFormat
  TEXT : String = "text"
[static] Specifies that downloaded data is received as text.
URLLoaderDataFormat
  VARIABLES : String = "variables"
[static] Specifies that downloaded data is received as URL-encoded variables.
URLLoaderDataFormat
Constant detail
BINARYconstant
public static const BINARY:String = "binary"

Language version: ActionScript 3.0
Runtime version: 

Specifies that downloaded data is received as raw binary data.

TEXTconstant 
public static const TEXT:String = "text"

Language version: ActionScript 3.0
Runtime version: 

Specifies that downloaded data is received as text.

VARIABLESconstant 
public static const VARIABLES:String = "variables"

Language version: ActionScript 3.0
Runtime version: 

Specifies that downloaded data is received as URL-encoded variables.

Examples
examples\URLLoaderDataFormatExample
The following example uses the URLLoaderDataFormatExample class to display data format and status information for a file loaded at runtime. This is accomplished using the following steps:
  1. The class constructor creates a URLLoader instance named loader and a URLRequest instance named request, which is the location and name of the file to be loaded.
  2. The loader object is passed to the configureListeners() method, which adds listeners for each of the supported URLLoader events:
    • completeHandler(): listens for the complete event, which is dispatched after TextFile.txt has successfully loaded.
    • openHandler(): listens for the open event, dispatched upon start of the download (to the player) of TextFile.txt.
    • progressHandler(): listens for the progress events, dispatched when data is received as the download operation progresses.
    • securityErrorHandler(): listens for securityError events, which would be dispatched if the text file was accessed with the wrong local playback security setting.
    • httpStatusHandler(): listens for httpStatusHandler events, which will not be dispatched in this case since TextFile.txt is local.
    • ioErrorHandler(): listens for ioError events, which would happen only if there were a serious problem with the file, such as if it were missing.
  3. The request object is then passed to the loader.load() method, which loads the text file into memory using a DisplayObject object.

Notes:


package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.*;

    public class URLLoaderDataFormatExample extends Sprite {
        private var source:String = "TextFile.txt";
        private var dataFormat:String = URLLoaderDataFormat.TEXT;
        private var loader:URLLoader;
    	
        public function URLLoaderDataFormatExample () {
            loader = new URLLoader();
            loader.dataFormat = dataFormat;
            configureListeners(loader);
            var request:URLRequest = new URLRequest(source);
            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Error loading requested document: " + source);
            }
        }

        private function configureListeners(dispatcher:URLLoader):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }

        private function completeHandler(event:Event):void {
            var loader:URLLoader = URLLoader(event.target);
            switch(loader.dataFormat) {
                case URLLoaderDataFormat.TEXT :
                    trace("completeHandler (text): " + loader.data);
                    break;
                case URLLoaderDataFormat.BINARY :
                    trace("completeHandler (binary): " + loader.data);
                    break;
                case URLLoaderDataFormat.VARIABLES :
                    trace("completeHandler (variables): " + loader.data);
                    break;
            }
        }

        private function httpStatusHandler(event:Event):void {
            trace("httpStatusHandler: " + event);
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }

        private function progressHandler(event:ProgressEvent):void {
            trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }
    }
}