1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
package {
import flash.net.URLLoader;
import flash.utils.Timer;
import flash.xml.XMLDocument;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
public class ChargeXML {
protected var items : Array;
protected var loader : URLLoader;
protected var xml : XMLDocument;
public function ChargeXML(str : String) : void {
//craete teh urlloader object
this.loader = new URLLoader();
this.items = new Array();
//craete a new flash.xml xmlDocuments object
this.xml = new XMLDocument();
//ignore the white spaces in the file
xml.ignoreWhite = true;
//set the loaders listener function that gets the event when the xml is loaded
this.loader.addEventListener(Event.COMPLETE, XMLloaded);
this.loader.addEventListener(ProgressEvent.PROGRESS, avancement);
//load the xml file from it's location
this.loader.load(new URLRequest(str));
trace(" Constructeur :" + this.items);
}
private function avancement(e:Event):void {
trace(e.target.bytesLoaded + " / " + e.target.bytesTotal);
}
private function XMLloaded(e:Event):void {
//parse the content and create a xml structure in the xmlDoscument
this.xml.parseXML(loader.data);
//firstchild represents first node, childNodes represent the nodes in the firstChild
for(var i:int = 0; i < xml.firstChild.childNodes.length; i++){
var o:Object = xml.firstChild.childNodes[i].attributes;
//pushing the item to the items array holding the mobiles
this.items.push(o.image);
}
trace(" XMLloaded :" + this.items);
}
public function getItems():Array {
trace(" getItems :" + this.items);
return this.items;
}
}
} |
Partager