how to parse xml with string path

okay,

so I have been making a very slow--VERY SLOW--conversion to AS3.  Mostly because my job duties changed for a bit and i was doing more design work than programming.  But here I am again back at the programming side of things. YEA!

My Point:

I am trying to write my xml loader as reusable object in itself.  So that when another object that relies on xml data is loaded it just simply calls my xml object and then goes from there.  I have attached my code below, but this does not work--completely.  it shows the path but still tells me code no joy! in the out put window.  any ideas what i am missing / doing wrong?

Thanks for your help in advance.

-Frankie
package {
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.xml.*;

	public class XMLEngine extends MovieClip {
		public var xmlPath:String;
		private var theXML:XML;
		private var loader:URLLoader;
		public function XMLEngine() {
			//constructor
		}
		private function loadXML(request):void {
			var loader:URLLoader=new URLLoader();
			loader.addEventListener(Event.COMPLETE,completeHandler);
			try {
				loader.load(request);
			} catch (error:Error) {
				trace('we have code no joy!');
			}
		}
		private function completeHandler(e:Event) {
			var loader:URLLoader=URLLoader(e.target);
			var result:XML=new XML(loader.data);
			var myXML:XMLDocument=new XMLDocument();
			myXML.ignoreWhite=true;
			myXML.parseXML(result.toXMLString());
		}
		public function getPath(urlPath:String) {
			if (urlPath) {
				xmlPath=urlPath;
				trace("theXML.load("+xmlPath+")");
				loadXML(xmlPath);
			}
		}
	}
}

Open in new window

frankybonesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

blue-genieCommented:
hello not sure how you implement it but here's the solution:

    private function loadXML(url:String):void {
                        var loader:URLLoader=new URLLoader();
                        loader.addEventListener(Event.COMPLETE,completeHandler);
                        try {
                                loader.load(new URLRequest(url));
                                                trace("loaded");
                        } catch (error:Error) {
                                trace('we have code no joy!' + error); <-- see here i'm outputting the error so I know what's wrong.....
                        }
                }

and the problem is Type Coercion failed: cannot convert "test.xml" to flash.net.URLRequest. <-- tells me this is wrong.....

so then you see the loader.load() expects a URLRequest but you're passing a string hence this change

loader.load(new URLRequest(url)); <-- i changed the argument to url to prevent confusion.


blu.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
frankybonesAuthor Commented:
you rock as usual blue, thank you for taking a look-see!
0
frankybonesAuthor Commented:
To answer your question of how I plan to implement the code.  The idea I am using is to have the XMLEngine class as it's own object that other objects extend or import.  Have not figured out how to do that just yet, as I am still getting the hang of the new syntax and OOP.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.