|
|
Loading an XML file To load an XML file takes 4 lines of code (actionscript 3 is required) Create a loader object, load the xml file, what for it to completely load, display it var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, loadXML); loader.load(new URLRequest(“my.xml”)); function loadXML(e:Event):void { var xml:XML = new XML(e.target.data); trace(xml); } Accessing elements in the XML file To access an attribute in the XML file in flash. i.e. .. trace(xml.weather.current_conditions.temp_f.@data); or trace(xml.weather.current_conditions[0].temp_f.@data); // if there are multiple current_conditions in the file .. Output: 34 Which corresponds to this XML file: <weather> <current_conditions> <temp_f data="34" /> </current_conditions> </weather> To access the text portion of the XML file in flash. .. trace(xml.weather.current_conditions.temp_f.text();) or trace(xml.weather.current_conditions.temp_f.text()[0];) // if multiple elements .. Output: 34 Which corresponds to this XML file: <weather> <current_conditions> <temp_f>34</temp_f> </current_conditions> </weather> References Livedocs reference of XML class |
||
| |||||||||||||||||||||