[cc lang=”actionscript3″]
class XMLShortcutsExample
{
function XMLShortcutsExample ()
{
//Activate the XML Shortcuts
XMLShortcuts.activate ();
//Create an XML Object
//Note: Avoid declaring as XML
var my_xml = new XML ()
//ignoreWhite=true is not a must for XML Shortcuts, but it can improve performance
//for the sake of display we ignore it here
//_xml.ignoreWhite=true;
my_xml.onLoad = function (success)
{
if (success)
{
_root.t1_txt.text += “Original XML:n” + this;
_root.t2_txt.text += “my_xml.english.a = ” + my_xml.english.a + “rn”;
_root.t2_txt.text += “my_xml.english.a_1 = ” + my_xml.english.a_1 + “rn”;
_root.t2_txt.text += “my_xml.english.$b = ” + my_xml.english.$b + “rn”;
_root.t2_txt.text += “my_xml.english.c._word = ” + my_xml.english.c._word + “rn”;
_root.t2_txt.text += “my_xml.english.c.__text = ” + my_xml.english.c.__text + “rn”;
_root.t2_txt.text += “my_xml.english.a_1.nodeIndex = ” + my_xml.english.a_1.nodeIndex + “rn”;
_root.t2_txt.text += “my_xml.english.c.rootNode instanceof XML = ” + (my_xml.english.c.rootNode instanceof XML) + “rn”;
}
}
//Load the XML
my_xml.load (“XMLShortcutsExample.xml”);
var tf : TextFormat = new TextFormat ();
tf.font = “Courier”;
//Create a TextFied to display
_root.createTextField (“t1_txt”, 0, 0, 0, 300, 400);
_root.t1_txt.text = “XMLShortcutsExample:nn”;
_root.t1_txt.setNewTextFormat (tf);
_root.createTextField (“t2_txt”, 1, 300, 0, 500, 400);
_root.t2_txt.text = “XMLShortcuts Usage:nn”;
_root.t2_txt.setNewTextFormat (tf);
_root.t2_txt.background = true;
_root.t2_txt.backgroundColor = 0xDDDDDD;
}
static function main () : Void
{
var app : XMLShortcutsExample = new XMLShortcutsExample ();
}
}
[/cc]