Flash XML processing


Home - Tutorials - Actionscript

Flash XML processing is not a complicated task at all. In this article I will show you how to load and process XML files via actionscript.

Tutorial info:


Name:Flash XML processing
Total steps:2
Category:Actionscript
Date:2007-11-11
Level:Beginner
Product:See complete product
Viewed:40194

Bookmark Flash XML processing



AddThis Social Bookmark Button

Step 1 - XML basics


Flash XML processing

Nowadays XML is very popular. Storing data in XML format makes it platform independent and various applications can process it easily. Of course Flash also has built in routines to help us working with XML files. As a result, the use of XML processing is now more common than ever. With most people having fast and reliable internet access from providers such as O2, more internet users are able to benefit from Flash features. In order for data to be processable via a wide range of platforms, it is a good idea to understand how to put together your own XML actionscript. Here is a basic guide on how to do so.

In this article we will use an XML file which describes a photo gallery. The XML stores the title of the photo and the image file location. It look like this:

Code:
  1. <?xml version="1.0"?>
  2. <gallery name="Photo gallery">
  3. <image name="Picture_1" location="gallery/photo1.jpg" />
  4. <image name="Picture_2" location="gallery/photo2.jpg" />
  5. <image name="Picture_3" location="gallery/photo3.jpg" />
  6. </gallery>

The first line defines the XML format and the real data begins from the second line. In this example we have a gallery with 3 images. To be safe you should save your XML files in UTF-8 format, else Flash can have some problem with the file.

Now it's time to make some actionscript. First of all we need to create a special XML object. This object will handle our XML file. The code is the following:

Code:
  1. var myPhoto:XML;
  2. myPhoto = new XML();

After we have created our XML object we can call its load() function to load our XML file as follows:

Code:
  1. var myPhoto:XML;
  2. myPhoto = new XML();
  3. myPhoto.load("gallery.xml");

XML files can contain nodes that contain only white space. These nodes can cause some troubles so we need to ignore them. Fortunately we can do it quite easy just setting the ignoreWhite parameter to true:

Code:
  1. var myPhoto:XML;
  2. myPhoto = new XML();
  3. myPhoto.ignoreWhite = true;
  4. myPhoto.load("gallery.xml");

In the next section we will process the loaded file.




Next Step of Flash XML processing


Tags: flash xml processing, actionscript xml processing, flash xml, actionscript xml, flash, xml

Flash XML processing - Table of contents
Step 1 - XML basics
Step 2 - Process XML data


Host Addon Ltd

F1 Site Family
AJAX F1
CSS F1
Database F1
Flash F1
HTML F1
Java F1
JavaScript F1
PhotoShop F1
PHP F1
Scripts F1
Tutorial F1
Windows F1

Total time: 0.245