Monday, April 13, 2009

New XMLLoader 3.0 Release

I have finally gotten around to updating the XMLLoader Class now, in its 3rd Release. With this release comes a couple new properties such as bytesLoaded, bytesTotal, totalItems, currentItem and ratioLoaded. The biggest update is the new naming feature. With this feature you can now give each XML file a name to reference it. Also in the big boat of updates is the new way of handling errors.


The new naming feature is meant to replace the old naming feature in version 2.0. TO refresh everyone's memories, the older version would automatically name the file for you by using the actual name of the file. If there happened to be more than one file that had the same name, it would attach a number depending on its spot in the Array. I've come to realize, this way was really unproductive and annoying. So to combat that, I created a new naming feature. This naming feature allows you to call each XML file anything you you want.

In order to use this new feature, you must pass in another Array which contains the names in the order that the XML files are being loaded in. For Example:




package
{
import com.clementegomez.utils.XMLLoader;
import flash.display.*;
import flash.events.*;

public class XMLDoc extends MovieClip
{
public var xl:XMLLoader;
public var array:Array;
public function XMLDoc()
{
xl = new XMLLoader();
array = new Array();
xl.addEventListener(Event.COMPLETE, loaded);

xl.loadXML(["http://flashden.net/feeds/user_item_comments/cg219.atom", "http://feeds2.feedburner.com/kreativeking?format=xml"], ["xml1", "xml2"]);
}

private function loaded(e:Event):void
{
trace(xl.data["xml1"]);
}
}
}


In the previous example, we pass in a second array of strings to the loadXML() function. the first string "xml1" will be the name of the first XML file in the array and "xml2" refers to the second. With this, you can reference the XML file by name later on in code rather than its index number.

The new properties include ratioLoaded which returns the amount of items loaded to the total amount of items as a Number between 0 and 1. The currentItem property returns the number of the current XML being loaded and the totalItems property returns the total amount of XML files. The bytesLoaded and bytesTotal return those properties of the current XML file being loaded.

The new Error handling has been improved as well. A new property has been added called skipErrors. This is set to true by default. When this property is set to true, if there happens to be an error in the Array of XML files such as a dead link or misspelled url, it will be skipped and the loading process will continue. This is set to true by default, so if you would like to receive the Error messages, set this property to false.

Official Documentation can be found here
Download the Class files here

1 comment:

  1. hello, broken links or whatesle in XMLLoader? CHEERS.

    ReplyDelete