Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  How to Load Data and Use it From XML

How to Load Data and Use it From XML

By Victor Gaudioso | Published 03/12/2007 | Beginner | Rating:
Victor Gaudioso
Victor Gaudioso is a Sr. Application developer for an advertising firm in Hollywood, CA.  He specializes in Flash / ActionScirpt but also programs in other languages including but not limited to C#, XAML, WPF and ASP .NET.  He has engineered Flash sites for the major entertainment studios including Disney, Universal, TouchStone, Mattel and Warner Bros. among others. Victor is known as dvlnblk in the http://actionscript.org forums and has recently been appointed a site moderator.  AIM: dvlnblk2004 Yahoo: victoratdeadline 

View all articles by Victor Gaudioso
Create the XML document

I see this question over and over again in the forums so I decided to create a very quick and simple tutorial that shows how to load data in from an xml page and use it in Flash.

First I create a simple xml document called images.xml.  Here is the code:

<images>
 <image image="img/img1.jpg" caption="Victor Gaudioso - Flash Programmer"/>
</images>


We are only going to use one simple xml node to keep it simple.  Save this file in a directory called xml.



Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Comments
  • Comment #1 (Posted by Mike Steffler - mikesteffler at hotmail.com)
    Rating
    I've always found this to be a neater way to loop through loaded XML:
    my_xml.onLoad = function()
    {
    for(var i = this.firstChild.firstChild; i; i = i.nextSibling)
    {
    trace(i.nodeName + ": " + i.firstChild.nodeValue);
    }
    };
     
  • Comment #2 (Posted by pixelmana - pixelmana at yahoo.com)
    Rating
    it's better to check the load result with onLoad fuction:

    obj.onLoad = function(success:Boolean):Void {
    if (success) {
    if (this.status == 0) {
    // success
    } else {
    // failed to parse the xml
    }
    } else {
    // path not found
    }
    }
     
  • Comment #3 (Posted by got_u_shook - got_u_shook at yahoo.com)
    Rating
    Works only for jpg. Failed with gif
     
  • Comment #4 (Posted by David G - dgladden at kpmg.com)
    Rating
    I'm an extremely new user of Flash and Actionscript, and I have a very basic question:

    What is an "AS Layer" and how do I create on?

    -Thanks
     
  • Comment #5 (Posted by Nobody)
    Rating
    I was disappointed that this didn't work for GIFs. :(

    "What is an "AS Layer" and how do I create on?"

    I assume "AS Layer" is short for "ActionScript Layer." Such a layer would have ActionScript code applied to a frame (or frames) on that layer, but the layer would not be used for anything else (such as text or image placement/animation).
     
  • Comment #6 (Posted by Ashwini - ashwinink at yahoo.com)
    Rating
    How can I change the image size. Do I have to process the image to the desired width and height or can I change it
     
  • Comment #7 (Posted by Grapplica - lander at grapplica.be)
    Rating
    I keep getting an error report »
    1120: Access of undefined property numOfItems on numOfItems = nodes.length;
    and a second for the source of »
    for (var i = 0; i<numOfItems; i++)

     
  • Comment #8 (Posted by grapplica - lander at grapplica.be)
    Rating
    Weirdly the downloaded zip doesn't populate the xml either.
     
  • Comment #9 (Posted by Coyote - codyflis at gmail.com)
    Rating
    Had a similar error and changed it to a AS 2.0 file and it worked fine.
     
  • Comment #10 (Posted by Tracy - tnagy123 at hotmail.com)
    Rating
    I would like some further explanation as to what parts of the code relate to what parts of the xml, how to load in more complex xml and something along those lines.
     
  • Comment #11 (Posted by mpuglisi - michael at mpuglisi.com)
    Rating
    Thank you. This was very helpful. I am wondering though, how do I add a loop to this code? I want the last image to be followed by the first image in the XML file.

    Thanks.
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.