Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts

    How to change XML categories

    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.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 1 Time in 1 Post
    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:
    Code:
    <?xml version="1.0" ?>
    <menu>
      <item itemtype = "demonic">
    	<name>demonic_img001</name>
    	<file>demonic_img001</file>
    </item>
    <item itemtype =  "demonic">
    	<name>demonic_img002</name>
    	<file>demonic_img002</file>
    </item>
    <item itemtype = "demonic">
    	<name>demonic_img003</name>
    	<file>demonic_img003</file>
    </item>
    <item itemtype = "insanity">
    	<name>insanity_img_001</name>
    	<file>insanity_img_001</file>
    </item>
    <item itemtype = "insanity">
    	<name>insanity_img_002</name>
    	<file>insanity_img_002</file>
    </item>
    <item itemtype = "undead">
    	<name>undead_img_001</name>
    	<file>undead_img_001</file>
    </item>
    <item itemtype = "undead">
    	<name>undead_img_002</name>
    	<file>undead_img_002</file>
    </item>	
    </menu>
    ActionScript:
    Code:
    // 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'){
    	Get_DemonicArray(i);
     }
     else if(linklist.childNodes[i].attributes.itemtype == 'insanity'){
    	Get_InsanityArray(i);
    }
     else{
    	Get_UndeadArray(i);
     } 
    }
    
    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;
    	iad++;
    }
    
    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;
    	iai++;
    }
    
    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;
    	iau++;
    }
    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.

    Code:
    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");
        new_num_d++;
    //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.
    if ( atfirst != succeed)
    tryagain();

  • Users who have thanked Frank for this post:

    marilynn.fowler (06-15-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •