-
Using as XML
I want to know why I can't use this code
PHP Code:
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
function xmlloaded(e:Event):void {
xml=e.target.data as XML;
trace(xml.toString());
}
loader.load(new URLRequest('photogallery.xml'));
loader.addEventListener(Event.COMPLETE,xmlloaded);
I know the problem is
Code:
xml=e.target.data as XML;
but I want to know why I can't use the as XML instead of XML(e.target.data)?
thank you
-
Try
PHP Code:
xml = new XML(loader.data)
The way you are doing it, I think only works for DataEvents.
-
Using the as operator casts one class to another. It only works if that object actually IS an instance of the cast-to class. Strings are not XML.
Using XML(data) or new XML(data) actually calls functions which parse the string into XML. The syntax is very misleading since you would think that XML(data) is casting data to XML, but in fact there is a top-level XML function which converts an object to XML.