13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

HTTP communications<br />

private function completeHandler(ev<strong>en</strong>t:Ev<strong>en</strong>t):void<br />

{<br />

var loader2:URLLoader = URLLoader(ev<strong>en</strong>t.target);<br />

var variables:URLVariables = new URLVariables(loader2.data);<br />

trace(variables.dayNames);<br />

}<br />

Each name-value pair from the external file is created as a property in the URLVariables object. Each property within<br />

the variables object in the previous code sample is treated as a string. If the value of the name-value pair is a list of items,<br />

you can convert the string into an array by calling the String.split() method, as follows:<br />

var dayNameArray:Array = variables.dayNames.split(",");<br />

If you are loading numeric data from external text files, convert the values into numeric values by using a top-level<br />

function, such as int(), uint(), or Number().<br />

Instead of loading the cont<strong>en</strong>ts of the remote file as a string and creating a new URLVariables object, you could instead<br />

set the URLLoader.dataFormat property to one of the static properties found in the URLLoaderDataFormat class.<br />

The three possible values for the URLLoader.dataFormat property are as follows:<br />

URLLoaderDataFormat.BINARY—The URLLoader.data property will contain binary data stored in a ByteArray<br />

object.<br />

URLLoaderDataFormat.TEXT—The URLLoader.data property will contain text in a String object.<br />

URLLoaderDataFormat.VARIABLES—The URLLoader.data property will contain URL-<strong>en</strong>coded variables stored<br />

in a URLVariables object.<br />

The following code demonstrates how setting the URLLoader.dataFormat property to<br />

URLLoaderDataFormat.VARIABLES allows you to automatically parse loaded data into a URLVariables object:<br />

Last updated 6/6/2012<br />

816

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!