Created
March 23, 2011 19:37
-
-
Save rafaelrinaldi/883783 to your computer and use it in GitHub Desktop.
A test showing how to use embedded XML files in ActionScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<document> | |
<foo>This is my document</foo> | |
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import flash.utils.ByteArray; | |
import flash.display.Sprite; | |
/** | |
* | |
* @author Rafael Rinaldi (rafaelrinaldi.com) | |
* @since 23/02/2011 | |
* | |
* */ | |
public class EmbeddedXMLTest extends Sprite { | |
[Embed(source="document.xml", mimeType="application/octet-stream")] | |
protected const document : Class; | |
public function EmbeddedXMLTest() { | |
trace(xml(document)); | |
/* | |
<document> | |
<foo>This is my document</foo> | |
</document> | |
*/ | |
} | |
public function xml( p_class : Class ) : XML { | |
const byteArray : ByteArray = new p_class as ByteArray; // Parsing the XML data as ByteArray | |
return new XML(byteArray.readUTFBytes(byteArray.length)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tea.util | |
{ | |
import flash.utils.ByteArray; | |
/** | |
* | |
* Simple parser for embedded XML files. | |
* | |
* @param p_klass Document class. | |
* @return A XML instance based on document's bytes. | |
* | |
* @author Rafael Rinaldi (rafaelrinaldi.com) | |
* @since 23/03/2011 | |
* | |
* */ | |
public function parseEmbeddedXML( p_klass : Class ) : XML | |
{ | |
const bytes : ByteArray = new p_klass as ByteArray; | |
return new XML(bytes.readUTFBytes(bytes.length)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment