| Package | flash.net | 
| Class | public final class URLLoaderDataFormat | 
| Inheritance | URLLoaderDataFormat    Object | 
| Language Version: | ActionScript 3.0 | 
| Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 | 
Public Properties
| Property | Defined By | ||
|---|---|---|---|
![]()  | constructor : Object 
	 A reference to the class object or constructor function for a given object instance.  | Object | |
Public Methods 
| Method | Defined By | ||
|---|---|---|---|
![]()  | 
	 Indicates whether an object has a specified property defined.  | Object | |
![]()  | 
	 Indicates whether an instance of the Object class is in the prototype chain of the object specified 
	 as the parameter.  | Object | |
![]()  | 
	 Indicates whether the specified property exists and is enumerable.  | Object | |
![]()  | 
     Sets the availability of a dynamic property for loop operations.  | Object | |
![]()  | 
	 Returns the string representation of this object, formatted according to locale-specific conventions.  | Object | |
![]()  | 
	 Returns the string representation of the specified object.  | Object | |
![]()  | 
	 Returns the primitive value of the specified object.  | Object | |
Public Constants
| Constant | Defined 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
BINARY | Constant | 
public static const BINARY:String = "binary"| Language Version: | ActionScript 3.0 | 
| Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 | 
Specifies that downloaded data is received as raw binary data.
TEXT | Constant | 
public static const TEXT:String = "text"| Language Version: | ActionScript 3.0 | 
| Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 | 
Specifies that downloaded data is received as text.
VARIABLES | Constant | 
public static const VARIABLES:String = "variables"| Language Version: | ActionScript 3.0 | 
| Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4 | 
Specifies that downloaded data is received as URL-encoded variables.
Examples How to use this example 
URLLoaderDataFormatExample.as
 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:
 
- The class constructor creates a URLLoader instance named 
loaderand a URLRequest instance namedrequest, which is the location and name of the file to be loaded. - The 
loaderobject is passed to theconfigureListeners()method, which adds listeners for each of the supported URLLoader events:completeHandler(): listens for thecompleteevent, which is dispatched after TextFile.txt has successfully loaded.openHandler(): listens for theopenevent, dispatched upon start of the download (to the player) of TextFile.txt.progressHandler(): listens for theprogressevents, dispatched when data is received as the download operation progresses.securityErrorHandler(): listens forsecurityErrorevents, which would be dispatched if the text file was accessed with the wrong local playback security setting.httpStatusHandler(): listens forhttpStatusHandlerevents, which will not be dispatched in this case since TextFile.txt is local.ioErrorHandler(): listens forioErrorevents, which would happen only if there were a serious problem with the file, such as if it were missing.
 - The 
requestobject is then passed to theloader.load()method, which loads the text file into memory using aDisplayObjectobject. 
Notes:
- You will need to compile the SWF file with "Local playback security" set to "Access local files only".
 - This example requires that a file named TextFile.txt be placed in the same directory as your SWF file. If you would like to see this example identify binary or URL-encoded data files, you will need to provide the file in the proper data format and change TextFile.txt to the name and location of the new file.
 
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);
        }
    }
}
Thu Dec 4 2014, 05:50 PM -08:00
 