kreativeKING - Interactive Developer

Posts tagged “XML”

Cool Flash Tip of the Week 4

I know last week I said we will be learning about a custom class, but I think I’ll hold that one for next week. This week we are going to check out a quick and useful tip that I didn’t even know about until a couple of days ago for selecting XML and XMLList nodes. This won’t be as in depth as the last, but I still think its a great quick tip.













We will be testing on this XML file.







Maria
Jason


Jason


Chris
Jack
Maria





I recently found out this cool way to select XML nodes. You can actually test attributes to filter out which ones you want. Check out the example for a better idea of what I mean.





var l:URLLoader = new URLLoader();
l.addEventlistener(Event.COMPLETE, xmlLoaded);
l.load(new URLRequest("ourXML.xml"));

function xmlLoaded(e:Event):void
{
var myXML:XML = XML(l.data);
trace(myXML.family.(@lastName == "Travis").member); // Outputs Maria , John
}



Using this method you can easily filter out a selection of nodes based on an evaluation. I find this a better way to the alternative of using array indices to select a particular tree. This is a pretty quick tip that I thought would be helpful. Next week, we are back to the in depth tips like usual. Again, if you like the post, subscribe to the RSS Feed.

kreativeMP3 - MP3 Player



  • Technologies

    - Actionscript 3.0, XML




  • Brief

    - Nice, advanced audio player with simple controls.




  • Features


  • - ID3 Tags support (Up to v2.4)

  • - Loop and Shuffle functionality

  • - Animated Volume Slider

  • - Live Scrubbing

  • Purchase Here

kreativeROTATE - XML Banner Rotator



  • Technologies



    - Actionscript 3.0, XML



  • Brief



    - Simple and clean banner / image rotator. XML driven slide show which supports links and loads JPEGS , PNGS, GIFS and SWFS .


  • Purchase Here

XMLLoader Class



  • Languages



    - Actionscript 3.0



  • Brief



    - This Actionscript 3.0 Class allows for multiple XML files to be loaded and stored for future use by way of a name or index number. I use this class in all of my XML powered projects.


  • Download Here

  • Watch ScreenCast

XMLLoader 3.0 Update

Fixed a small bug that was confusing the names and actual data. Link in the last post has been updated to the bug fixed version. This is just a courtesy posy to the ones who have already downloaded the class to download it again. Enjoy and keep me updated on bugs you may find or features you would like in the future.

I’m always available @cg219.


Download Link

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

XMLLoader 2.0 Update***

I’ve been getting some complaints about the XMLLoader.

First I have to say I missed a file when packaging it for distribution. I have already fixed that and you can redownload to get the updated package.

Secondly, for people getting a host of errors and the Error message is “Loading Failed”. This is because you have cacheBuster set to true. The cacheBuster must be set to false when testing locally.

If any other bugs pop up, don’t hesitate to drop me a line. Thanks again for the feedback, this wouldn’t have been caught without your help.

Enjoy


Download XMLLoader Class 2.0 Here

XML Based Navigation

Just something I whipped up trying to build up my portfolio of web elements. This navigation element grabs the urls from an xml file, so you can update the links without having to open the flash file for fast updating of links. Any questions drop me a line.


[kml_flashembed movie=”http://blog.kreativeking.com/downloads/examples/navs/nav1.swf” height=”157.5” width=”560” base=”http://blog.kreativeking.com/downloads/examples/navs/” /]

Stable Release XMLLoader 2.0

**Update**
http://blog.kreativeking.com/2008/10/xmlloader-20-updatexmlloader-20-update/



I have been working hard on making this as robust and stable as possible. This release should be able to do anything you would like with loading XML. Couple of new features from 1.8 the community has been emailing me about as well as some that I wanted to include in past versions. I will be releasing a video tutorial on how to use this class properly. I’ll explain the new features to hold you over until then.





New Constructor



XMLLoader($url:Array = null, $cache:Boolean = false):void



In 2.0, the XMLLoader constructor now takes 2 parameters. The first, being the same as in past versions, an Array of the xml files being loaded. The second being a new feature called cacheBuster which I will get more into bit later. By default these are set to null and false respectively.



New Cachebuster Feature



XmlLoader 2.0 introduces the new Cachebuster feature. This feature allows you to always load up an up to date version of your XML File. This is will make it so your flash application will not used cached files. This parameter is takes a boolean value and can be set in two ways. One being in the constructor shown above. The second is by setting the cacheBuster property.



XMLLoader.cacheBuster = true;
XMLLoader.cacheBuster =false;



New way of referencing load XML’s



In past versions, to access a certain loaded XML file. Something like the code below would be used.



XMLLoader.getList["xmlfile.xml"];



In 2.0 the file extension is no longer accepted, just the name of the file like below.



XMLLoader.getList["xmlfile"];



Also in 2.0, if you have two loaded files that happen to have the same name. To access the other files after the first. You only need to put the name + underscore + array index. Here is an example.



var testXML:XMLLoader = new XMLLoader(["test.xml", "test2.xml", "test.xml", "test2.xml", "test.xml", "test2.xml"], true);
testXML.addEventListener(Event.COMPLETE, doIT);

function doIT(e:Event)
{
var list:XML;
list = testXML.getList["test_4"];
trace(list);
}



In the above code, the last test.xml will be loaded. The array index is its spot in the url array.



Those are the main new features in 2.0. Some other under the hood work includes some better error catching and proper event dispatching. The video tutorial should be out before the month is out as well as a new ite to host them, so look out for that. As always, let me know of any bugs and suggestions nd I will try to get to them ASAP.



Enjoy



Download XMLLoader Class 2.0 Here

**UPDATE** *NEW* XMLLoader Class v. 1.8

**Update**
XMLLoader 2.0 « Cleck Here

**UPDATE**
Build 1.8 had some back end updates.


  • Complete Event doesn’t dispatch early

  • XML Root is now passed instead of just the children




Syntax is still the same

As 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 easier to use. In this release v.1.6, 2 new features are introduced. You can now choose which list to get by the name of the xml file and now there is a new function to load xml outside of the constructor.


Here is an example of calling a list by ts name instead of the array number.


import com.clementegomez.utils.XMLLoader;

var testXML:XMLLoader = new XMLLoader();

testXML.loadXML(["test.xml", "test2.xml", "test.xml", "test2.xml"]);

testXML.addEventListener(Event.COMPLETE, doIT);

function doIT(e:Event)
{
var list:XMLList;
list = testXML.getList["test2.xml"];
trace(list);
}





The getList property returns an array, so to reference a list by its name you place the name within the [ ] brackets. Simple enough. You can still reference lists by there array number if this is more convenient for you.

The second new feature is the loadXML function. This basically does what the constructor did in previous versions. In the above code you can see how it is used. This is if you rather not load up your xml files in constructor. This can also be useful to define the XMLLoader and load your xml files later on in your script.

I hope you find this useful. Enjoy and like always suggestions and bug reporting is welcome.

Download XMLLoader Class Here

More Information