U pravu si, tako mi i treba kad odgovaram na frku.
Nego, ako sam dobro razumeo ti hoces vrednost svakog name node-a da stavis u Array i da mozes da mu pristupas iz druge funkcije.
Ukoliko je to slucaj, onda je ovo kod za Flash 8
Code:
import mx.utils.Delegate;
class pitanje extends MovieClip {
// declare vars needed for class
private var i:Number;
private var my_ar:Array;
private var xmlData:XML;
// initialize the vars, set the XML Object to ignore the white space,
// set the function that will be called for the XML onLoad event
function pitanje() {
my_ar = new Array();
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = Delegate.create(this,goto);
loadXML();
// if you call array function here you will get nothing back,
// since the loading has been started, it may not have completed yet
//array();
}
// start the loading of the xml file
private function loadXML() {
trace("loadXML");
xmlData.load("pitanje.xml");
}
//function that is called when the xml file is loaded,
// param success will be true for successfull loading of the xml file
function goto(success) {
if (success) {
// trace the whole xml file
trace(xmlData)
// set the root node
var rootNode:XMLNode = xmlData.firstChild;
// go through all the childnodes in the root node
for (i=0; i<rootNode.childNodes.length; i++) {
//var my_ar = new Array();
// and add their text values to the array
my_ar.push(rootNode.childNodes[i].firstChild);
// trace the current content of the my_ar array
trace("my_ar = " + my_ar);
}
// when you call the function here it will list the contents of
// the array, because the load has been completed and the xml
// has been parsed
array();
} else {
trace("crap")
}
}
// list the contents of the my_ar array
private function array() {
trace("array = " + my_ar)
}
}
output ove klase je:
Code:
loadXML
<?xml version="1.0" encoding="utf-8"?><pictures><name>auto</name><name>kuca</name><name>avion</name><name>kamion</name><name>lopta</name><name>olovka</name><name>knjiga</name></pictures>
my_ar = auto
my_ar = auto,kuca
my_ar = auto,kuca,avion
my_ar = auto,kuca,avion,kamion
my_ar = auto,kuca,avion,kamion,lopta
my_ar = auto,kuca,avion,kamion,lopta,olovka
my_ar = auto,kuca,avion,kamion,lopta,olovka,knjiga
array = auto,kuca,avion,kamion,lopta,olovka,knjiga