PDA

View Full Version : Error Loading XML in AS 3.0



Atrix78
May 26th, 2008, 08:48 PM
Hello, I'm trying to do the XML in AS 3.0 on this site, but the code doesn't work properly.

This code gives an error every time.

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(newURLRequest("http://www.kirupa.com/net/files/sampleXML.xml")); function LoadXML(e:Event):void { xmlData = new XML(e.target.data); trace(xmlData);}

I get type was not found or is not a compile time constant pointing to line 9
which is 'function LoadXML(e:Event):void {' Can someone explain how to fix
this and why it's causing an error?

adnan794
May 26th, 2008, 10:46 PM
I guess the problem here is when ur casting e.target.data into XML you dont have to use new keyword while doing that.

so just replace " xmlData = new XML(e.target.data); " with " xmlData = XML(e.target.data); "

This should work fine now

amarghosh
May 27th, 2008, 03:30 AM
I get type was not found or is not a compile time constant ____
where is the remaining part that explains what is the type missing?

i guess it says Event.
import it;

import flash.events.Event;

Atrix78
May 27th, 2008, 10:05 AM
where is the remaining part that explains what is the type missing?

i guess it says Event.
import it;
ActionScript Code:

import flash.events.Event;




That appears to have solved it. Thanks. I just copied the code supplied, there were no import statements listed in the tutorial.

Now it's pointing to the XML instead of Events.

Let's make this easier. What are the packages I have to import to start and finish the tutorial? Am I missing the reason they weren't actually included in the code?

amarghosh
May 28th, 2008, 01:15 AM
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/
bookmark this link. u can find what classes are in what packages from that;

u don't have to import XML as it is a top level class; are u sure error is pointing at XML?