This is the AS I use to connect to an XML file:
Actionscript Code:
// populates the text fields by callinging the functions
// "getValue" and "findNode", if it finds the xml document
function processXMLData (success) {
if (success) {
var rootNode = this.firstChild;
// Text
var text_1Node = findNode (rootNode, "text_1");
_global.text_1_ = getValue (text_1Node);
var text_2Node = findNode (rootNode, "text_2");
_global.text_2_ = getValue (text_2Node);
var text_3Node = findNode (rootNode, "text_3");
_global.text_3_ = getValue (text_3Node);
var text_4Node = findNode (rootNode, "text_4");
_global.text_4_ = getValue (text_4Node);
} else {
trace ("No XML found");
}
}
// functions that find and retrieve the data
function getValue (node) {
if (node && node.firstChild) {
return node.firstChild.nodeValue;
}
return "";
}
function findNode (node, nodeName) {
if (node.nodeName == nodeName) {
return node;
}
for (var i = 0; node.childNodes && i < node.childNodes.length; i++) {
var foundNode = findNode (node.childNodes[i], nodeName);
if (foundNode != null) {
return foundNode;
}
}
return null;
}
// this pulls in the XML doc and sets it = to xmlData
var xmlData = new XML ();
xmlData.ignoreWhite = true;
xmlData.onLoad = processXMLData;
xmlData.load ("Name_Of_Your_XML_Document.xml");
The functions are used for finding data and removing the node names so they don't get pushed into the text fields as well. By setting the nodes equal to global variables you can access them from anywhere in the swf. You'll also want to use CDATA in your XML doc. It allows you to detail your text with HTML settings.
Hope this helps!