PDA

View Full Version : Reading and parsing XML file Help


Whittler
03-12-2011, 01:54 AM
Hello to everyone in this forum. I'm a newb. Sorry if my post is not formatted correctly.

Can't seem to find any info on how to do this. I just want to read and parse my xml file into variables so I can display them and format them. I'm getting an error that reads:

TypeError: Error #1034: Type Coercion failed: cannot convert "m_products.xml" to flash.net.URLRequest.

This is my code snippet:

//create variables used later for getting/displaying xML info
var myXML:XML;
var itemNumber:uint = 0;
var myLoader:Loader = new Loader();
var totalItems:int = 0;

//create variables to hold the information retrieved from the XML file
var prodName:String;
var prodDescription:String;

//create object to get the XML information
var xmlLoader:URLLoader = new URLLoader();

//object now gets the XML file
xmlLoader.load(URLRequest("m_products.xml"));

//once the object has a hold of the data begin displaying it
xmlLoader.addEventListener(Event.COMPLETE, setupXMLData);

function setupXMLData(e:Event):void
{
myXML = new XML(xmlLoader.data);
totalItems = myXML.children().length() - 1;
}

function displayProduct():void
{
prodName = myXML.prodpage[itemNumber].prodname;
prodDescription = myXML.prodpage[itemNumber].proddescription;
}

trace(prodName);

Any help would be greatly appreciated.


Thanks

Whittler
03-12-2011, 02:04 AM
Disregard my request. I just figured out that instead of:

xmlLoader.load(URLRequest("m_products.xml"));

I should have included new:

xmlLoader.load(new URLRequest("m_products.xml"));

But now I have another error that reads:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file: etc...

Whittler
03-12-2011, 02:44 AM
Disregard everything... Sorry.

Whittler
03-12-2011, 02:44 AM
It's been great having a conversation with myself. Thanks self. ;-)