• Home
  • Free Tutorials
  • Free Video Tutorials

Adobe Photoshop
Autodesk 3ds Max
CSS
Flash
Help Center Live
iPhone
Joomla
Make Money Online!
Mambo
mIRC
Outlook Express
SEO / SEM
Simple Machine Forum
Target Explorer

Retrieve Data From XML File

Category : Flash Views : 27721
Version : 8 Rating : 
3.1/5 (59 votes)
  • Currently 3.08/5
  • 1
  • 2
  • 3
  • 4
  • 5
Type : Text Source File: retrieve-data-from-xml-file.zip
Result: See the result


XML files are a great option to customization in flash; you can simply create a XML and tell your movie to load variables from it.
Let's say you want to create a movie that randomly loads one of three images. But you think that later you may want to add more images or change their path, so you need a XML file.
That's what we are going to do is this tutorial.

First create the xml file:
<xml> <images> <a title = "pic1.jpg" /> <b title = "pic2.jpg" /> <c title = "pic3.jpg" /> </images> </xml>
You can add many more child nodes to <images> as long as you have those images inside the folder.

Save the xml as "images.xml" and create a button in your project.
Free Flash Tutorials, External Data, XML, External Sources, Retrieve Data from XML

Give it the instance name of "ranImage" and open the actions for the first frame.
Paste this code:
var images = new XML(); images.ignoreWhite = true; images.load("images.xml"); ranImage.onRelease = function() { var images_paths = _root.images.firstChild.firstChild.childNodes; var ran = Math.round(Math.random() * (images_paths.length - 1)); _root.createEmptyMovieClip("holder", 1); loadMovie(images_paths[ran].attributes.title, "holder"); _root.holder._xscale = 50; _root.holder._yscale = 50; } //Here we declare a new XML object var images = new XML() //Sometimes white spaces in a xml file can cause problems so we tell our XML object to ignore them images.ignoreWhite = true; //load() function, loads our .xml images.load("images.xml");

Here we declare a variable that corresponds to the child nodes of the <images> node in the xml file.
var images_paths = _root.images.firstChild.firstChild.childNodes;
Free Flash Tutorials, External Data, XML, External Sources, Retrieve Data from XML

Now we get a random number between 0 and the length of the images_paths array minus 1.
var ran = Math.round(Math.random() * (images_paths.length - 1))

Create a holder Movie Clip.
_root.createEmptyMovieClip("holder", 1);

Load the image.
loadMovie(images_paths[ran].attributes.title, "holder");

Title is an attribute of this node, so we need to call it like this inside our code:
(node).attributes.title

Scale the image.
_root.holder._xscale = 50; _root.holder._yscale = 50;

Try to add more images to the xml; you will notice that they will work exactly as they should.

This could also be very useful to create dynamic slideshows.

del.icio.us digg it Reddit Stumble Upon Technorati
How to Video Tutorials on software by Helpvids.com

Video tutorial: Forex trading



Sponsors



Advertisement









Studio | Advertisement | About Webzo | Contact Webzo | Terms of Use | Free Video Tutorials by Helpivds

Copyright © 2007 NR Concepts Ltd. All rights reserved.