View Full Version : How to change XML categories

06-13-2009, 08:30 PM
I have an XML file I'm using for a slideshow. I have three categories: demonic forces, insanity, and the undead. I have a button on my main stage for each of the categories. When you first come to the movie it automatically loads first slide. I would like to be able to click a button and have it only show me the images for that category. Is there a tutorial that I can view? I have been unsuccessful in finding one on my own.

06-14-2009, 03:57 PM
Without seeing any code or the fla file that you're working on it is hard to give you more precise help.

But here is what I would do.

You don`t include the .jpg or .gif in the xml <file> because it is taken care of in the actionscript.
XML File:

<?xml version="1.0" ?>
<item itemtype = "demonic">
<item itemtype = "demonic">
<item itemtype = "demonic">
<item itemtype = "insanity">
<item itemtype = "insanity">
<item itemtype = "undead">
<item itemtype = "undead">


// Keeps track of image loaded
var new_num_d = 0;
var new_num_i = 0;
var new_num_u = 0;

// Keeps track of array size
var iad = 0;
var iai = 0;
var iau = 0;

var demonic_array = new Array();
var insanity_array = new Array();
var undead_array = new Array();

linklist = database.childNodes[0]; // root xml items
linklength = linklist.childNodes.length; //xml item length

//Pulls info from xml to add to array
for (var i=0; i<linklength; i++) {

if (linklist.childNodes[i].attributes.itemtype == 'demonic'){
else if(linklist.childNodes[i].attributes.itemtype == 'insanity'){

function Get_DemonicArray(dnum){
demonic_array.push(new Array(1));
var dinum = dnum;
demonic_array[iad][0] = linklist.childNodes[dinum].childNodes[0].firstChild.nodeValue;
demonic_array[iad][1] = linklist.childNodes[dinum].childNodes[1].firstChild.nodeValue;

function Get_InsanityArray(inum){
insanity_array.push(new Array(1));
var iinum = inum;
insanity_array[iai][0] = linklist.childNodes[iinum].childNodes[0].firstChild.nodeValue;
insanity_array[iai][1] = linklist.childNodes[iinum].childNodes[1].firstChild.nodeValue;

function Get_UndeadArray(unum){
undead_array.push(new Array(1));
var uinum = unum;
undead_array[iau][0] = linklist.childNodes[uinum].childNodes[0].firstChild.nodeValue;
undead_array[iau][1] = linklist.childNodes[uinum].childNodes[1].firstChild.nodeValue;

Your button should then run a script that gets info from the right array and uses loadMovie to input it into an empty movie clip.

demonic_btn.onRelease = function(){
img_name_d = demonic_array[new_num_d][0];
thumb_img_d = "images/"+img_name_d+".jpg";
image_d.loadMovie(thumb_img_d,"demonic image");
//image_d is the instance name of the empty movie clip which is in a black graphic so you can control the size

Hope this helps.