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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.