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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Working with byte arrays<br />

There are two versions of AMF: AMF0 and AMF3. AMF 0 supports s<strong>en</strong>ding complex objects by refer<strong>en</strong>ce and allows<br />

<strong>en</strong>dpoints to restore object relationships. AMF 3 improves AMF 0 by s<strong>en</strong>ding object traits and strings by refer<strong>en</strong>ce, in<br />

addition to object refer<strong>en</strong>ces, and by supporting new data types that were introduced in ActionScript 3.0. The<br />

ByteArray.objectEcoding property specifies the version of AMF that is used to <strong>en</strong>code the object data. The<br />

flash.net.ObjectEncoding class defines constants for specifying the AMF version: ObjectEncoding.AMF0 and<br />

ObjectEncoding.AMF3.<br />

The following example calls writeObject() to write an XML object to a ByteArray, which it th<strong>en</strong> compresses using<br />

the Deflate algorithm and writes to the order file on the desktop. The example uses a label to display the message<br />

“Wrote order file to desktop!” in the AIR window wh<strong>en</strong> it is finished.<br />

/* The following lines, minus comm<strong>en</strong>t characters<br />

, are for Flex version:<br />

* <br />

* <br />

* <br />

* <br />

<br />

burger<br />

3.95<br />

<br />

<br />

fries<br />

1.45<br />

<br />

<br />

// Write XML object to ByteArray<br />

bytes.writeObject(myXML);<br />

Last updated 6/6/2012<br />

781

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

Saved successfully!

Ooh no, something went wrong!