Step2: Right-click first frame and select actions
Step3: Paste the below code in first frame
var xm:XML = new XML();//creating XML object
var name_arr:Array=new Array()//array objects to hold name data from xml
var age_arr:Array=new Array()//array objects to hold age data from xml
xm.ignoreWhite = true;//white spaces will be discarded
xm.onLoad = function() {//function will be call when xml file data loaded into xml object
var full_arr:Array=this.firstChild.childNodes//here we have array of child nodes
var len:Number=full_arr.length-1//getting the no of child nodes
for(var i:Number=0;i<=len;i++)//looping trough the values
{
name_arr[i]=full_arr[i].childNodes[0].firstChild//storing name values in array
age_arr[i]=full_arr[i].childNodes[1].firstChild //storing age details in array
trace([name_arr[i],age_arr[i],newline]);
}
};
xm.load("sample.xml");//loading the xml file data into xml object
Step4: save the file as example.fla
Step5: Create xml file (may be notepad and change extension from .txt to .xml)
Step6: Paste the below data in XML
<?xml version="1.0"?>
<root>
<student><name>sara</name><age>23</age></student>
<student><name>manju</name><age>25</age></student>
<student><name>sind</name><age>23</age></student>
</root>
Step7: Save under the same path where flash file is (file name: sample.xml)
Note: name of the xml file and path is more important
1 comments:
You should mention that this is AS2. The AS3 XML has the same name, but functions differently.
Post a Comment