Working with external data in Flash - XML Class
(Page 5 of 6 )
Extensible Mark-up Language (XML) is the future standard for exchanging structured data in Web based applications. Data in Flash can be integrated with servers that use XML technology to build sophisticated and effective, rich Internet applications.
ActionScript in Flash has a built-in XML class whose properties and methods can be used to load, parse, send, build, and manipulate XML document trees.
The methods load(), send(), and sendAndLoad() of the XML Class use HTTP or HTTPS protocol to send and load information as XML.
The load() method downloads XML from a URL and places it in an ActionScript XML object.
The send() method encodes the XML object into an XML document and sends it to a specified URL using the POST method. If specified, a browser window displays returned data.
The sendAndLoad() method sends an XML object to a URL. Any returned information is placed in an ActionScript XML object.
Apart from the above methods, the ActionScript XML Class has several other methods to let you structure the XML data in Flash to send to a server, and also to manipulate and interpret downloaded XML data from the server or file system. Methods and properties such as childNodes(), hasChildNodes(), attributes, firstChild, createElement(), and so forth let you parse and create XML files at run-time.
Now let us see a simple example for loading an external XML file into flash.
Example:
// create a new XML object
var sample_xml:XML = new XML();
// load the XML into the sample_xml object
sample_xml.load("sample.xml");
// set the ignoreWhite property to true to ignore white spaces and
new line characters in the XML document (default value is false)
sample_xml.ignoreWhite = true;
// onLoad event handler function which fires after the loading of
XML file is complete
sample_xml.onLoad = function(success) {
// you can perform actions on the loaded XML here
};
Next: XMLSocket Class >>
More Flash Articles
More By Adi Reddy Mora