Read XML Content using actionscript 2

1. Create a new flash file with actionscript 2

2. Create a XML object and load the xml file using load the method.
Code:

_xml = new XML(); // Create a xml object
_xml.load(“filename.xml”); // load the file to XML object
_xml.ignoreWhite = true; // remove the empty space between xml tag

3. Create a event for xml load method.

Code:

_xml.onLoad = function(success){
if (success){
// If the XML file content loaded successfully
getPlayerInfo(); // function load the xml values.
}
else
trace(“Error loading XML file”);
}

4. The content of getPlayerInfo function
Code:

function getPlayerInfo()
{
trace(_xml); // load the complete xml
trace(_xml.childNodes); // Load the first child node
trace(_xml.childNodes[0].childNodes); // get the child nodes of playlist
// get the attribute of song tag
trace(_xml.childNodes[0].childNodes[0].attributes.title);
trace(_xml.childNodes[0].childNodes[0].attributes.artist);
trace(_xml.childNodes[0].childNodes[0].attributes.src);
}

5. Run and get the xml file informations are in output panel

6. Check the Source file as attachment

admin

Back to top