**Update**
XMLLoader 2.0 « Cleck Here
I recently released a class (XMLLoader) and after some suggestions and further research, I decided to revamp the class entirely. With this comes some good news and bad news. Bad news first, the class no longer automatically creates the event listener for you. This is not a big lose. I just wanted to keep to Encapsulation standards.
That is the only bad news to report. Now for the GOOD news. I implemented some cool features in this release.
- Ability to load multiple XML files at once
- Supports Error Checking now
- Very Fast. Tested up to 3000 simultaneous loads in under a second
- Places each XML file in its own XMLList
- Easy Retrieval
With this new revision there are a couple differences from the original in its use.
New Syntax:
import com.clementegomez.utils.XMLLoader
//var instanceName:XMLLoader = new XMLLoader(Array);
var myXMLLoader:XMLLoader = new XMLLoader(["test.xml",
"test2.xml"]);
//Listener for when its done loading
myXMLLoader.addEventListener(Event.COMPLETE, doIT);
function doIT(e:Event)
{
//trace out the first list
trace(myXMLLoader.getList[0] + " is first
XML File")
//trace out the second list
trace(myXMLLoader.getList[1] + " is second
XML File")
}
There is only one accessible property in this class and thats to retrieve the lists.
getList Property
myXMLLoader.getList
This will return all of the XML files in the form of an Array. To access individual XMLLists add an array number after the getList property that coressponds the the list you want.
myXMLLoader.getList[0]
The above example will return the first XML file that was loaded. In our case it would be test.xml. If you wanted the second file you would replace the 0 with a 1 (All arrays start at number 0 not 1). To reuse a list, it would be best to store it inside a variable.
var myList:XMLList;
myList = myXMLLoader.getList
Or you can store a copy of the list in a variable.
var myList:XMLList;
myList = myXMLLoader.getList[0].copy()
This speeds up the process of handling XML in your project tremendously and also allows your code to be cleaner and less cluttered. I hope this new version serves the community well and if there are any suggestions or questions, don't hesitate to post them here.
Enjoy
Download Here XMLLoaderClass
Thanks for this, I'm going to take a look and I might use it in my current project
ReplyDeleteNo problem and thanks, let me know if you end up using it. I'll have more classes coming out shortly. Probably at the end of the week. I want to get some 3D stuff done first.
ReplyDeleteIs there something wrong with the example code? The event listener doesn't ever pull the xml from the e:Event variable... and it calls getList from testXML which isn't declared anywhere!
ReplyDelete"function doIT(e:Event)
{
//trace out the first list
trace(testXML.getList[0] + " is first
XML File")
//trace out the second list
trace(testXML.getList[1] + " is second
XML File")
}"
AH your right, I had a typo. Its fixed now. Replace textXML with myXMLLoader.
ReplyDeleteThanks for pointing that out
[...] many of you may already know, I built an XMLLoader class couple months ago. I have steadily been adding more features and making it more robust and [...]
ReplyDelete