Share Posted August 30, 2011 Hy@all, i have a little Problem with the XMLLoader I have here an AS3-project in which I will like to take Greensock LoaderMax to two XML files and the pictures that are in the XML files to preload. The XML files LoaderMax reads well, but as I am now on the contents of the XML. How can I now attribute to an instance of the XML Records access? my XML files: Code: <?xml version="1.0" encoding="UTF-8" ?> Code: <?xml version="1.0" encoding="UTF-8" ?> Here AS3 code Code: import com.greensock.loading.*; import com.greensock.loading.display.*; import com.greensock.events.LoaderEvent; ///////////////////////////// // XML Loader // //////////////////////////// LoaderMax.activate([imageLoader, SWFLoader, DataLoader]); //create an XMLLoader var areaLoader:XMLLoader = new XMLLoader("../xml/area.xml", {name:"xmlArea", requireWithRoot:this.root, estimatedBytes:1400}); var contLoader:XMLLoader = new XMLLoader("../xml/content.xml", {name:"xmlContent", requireWithRoot:this.root, estimatedBytes:1400}); //begin loading areaLoader.load(); contLoader.load(); //LoadHandler for XML Loader var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler}); var queue2:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler}); //append the XMLLoader and several other loaders queue.append( areaLoader ); queue2.append( contLoader); //begin loading queue queue.load(); queue2.load(); This is my code from completeHandler: function completeHandler(event:LoaderEvent):void { if(event.target.name == "areaXML"){ var areaXML:XML = new XML(areaLoader.content); areaXML.ignoreComments = true; areaXML.ignoreWhitespace = true; trace(areaXML); var anzahl = areaXML.item.length(); for(var i:int = 0;i trace(areaXML.item[i].@id); } } } I tried to put the data from getContent () into an XML object, but since then I could not drive the childs. Does anyone have a tip for me or any advice? Greetings Mah1987 Link to comment Share on other sites More sharing options...
Share Posted August 30, 2011 It is a bit difficult to understand exactly what you want to do. I'm guessing English isn't your first language and that's ok. When seeking help it is best to provide the least amount of code possible to get to a solution. Right now the loading of 2 xml files and preloading images seems to clutter the issue of parsing attributes in the xml. I've made an example of how to parse one of the xml files and access the various attributes: xmlContent.xml AS3 parsing code import com.greensock.*; import com.greensock.events.LoaderEvent; import com.greensock.loading.XMLLoader; var myXML:XMLLoader = new XMLLoader("xmlContent.xml", {onComplete:getXML}); myXML.load(); function getXML(e:LoaderEvent):void{ var loadedXML:XML = myXML.content as XML; trace("this is all the xml"); trace(loadedXML); //create an XMLList of just the content nodes var contentXML:XMLList = loadedXML..content; trace("\n\ncontent XMLList"); trace(contentXML); trace("\n\nthe id of the first content") trace(contentXML[0].@id); trace("\n\nloop through the id and discription of all content") for(var i:uint = 0; i trace(contentXML[i].@id + " : " + contentXML[i].@discription); } } there is an fla and sample xml attached. When you test the swf you will see many descriptive traces If you truly do intend to load an XML file and have all the images preload it would be much easier to do something like this: http://www.snorkl.tv/2011/08/loading-im ... xmlloader/ also the XMLLoader documentation has sample code of loading multiple assets from xml and adding description attributes. http://www.greensock.com/as/docs/tween/ ... oader.html by using the rawXML (as mentioned in the link above) you can attach any amount of formatted data to your loaders Link to comment Share on other sites More sharing options...
Author Share Posted August 31, 2011 It is a bit difficult to understand exactly what you want to do. I'm guessing English isn't your first language and that's ok. Yes, English is not my first language. I come from Germany. When seeking help it is best to provide the least amount of code possible to get to a solution. OK, for the future i know it. var loadedXML:XML = myXML.content as XML; var contentXML:XMLList = loadedXML..content; These two lines, I have sought, now i can handle the XML als an XML.object. Thanks alot! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now