Flash AS3 load file xml
- by Elias
Hello,
I'm just trying to load an xml file witch can be anywere in the hdd, this is what I have done to browse it, but later when I'm trying to load the file it would only look in the same path of the swf file
here is the code
package {
import flash.display.Sprite;
import flash.events.;
import flash.net.;
public class cargadorXML extends Sprite {
public var cuadro:Sprite = new Sprite();
public var file:FileReference;
public var req:URLRequest;
public var xml:XML;
public var xmlLoader:URLLoader = new URLLoader();
public function cargadorXML() {
cuadro.graphics.beginFill(0xFF0000);
cuadro.graphics.drawRoundRect(0,0,100,100,10);
cuadro.graphics.endFill();
cuadro.addEventListener(MouseEvent.CLICK,browser);
addChild(cuadro);
}
public function browser(e:Event) {
file = new FileReference();
file.addEventListener(Event.SELECT,bien);
file.browse();
}
public function bien(e:Event) {
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
req=new URLRequest(file.name);
xmlLoader.load(req);
}
public function loadXML(e:Event) {
xml=new XML(e.target.data);
//xml.name=file.name;
trace(xml);
}
}
}
when I open a xml file that isnt it the same directory as the swf, it gives me an unfound file error.
is there anything I can do?
cause for example for mp3 there is an especial class for loading the file, see http://www.flexiblefactory.co.uk/flexible/?p=46
thanks