A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: unique listing from array XML AM I MISSING SOMETHING???!?!?!

  1. #1
    Denied ACCESSORIES
    Join Date
    Dec 2000
    Location
    Rio de Janeiro
    Posts
    208

    unique listing from array XML AM I MISSING SOMETHING???!?!?!

    Ok now I know i just missing something here...In any case heres the xml code:
    PHP Code:
      <?xml version="1.0" standalone="yes" ?> 
    <rss version="2.0">
        <channel>
            <category>summer</category>
            
            <date>    
                June 4th 2002
            </date>
            <description>
                dafdafdsa
            </description>
        </channel>
        <channel>
            <category>winter</category>
            
            <date>    
                July 4th 2001
            </date>
            <description>
                dafdafda
            </description>
        </channel>
        <channel>
            <category>spring</category>
            
            <date>    
                Febuary 4th 2003
            </date>
            <description>
                dsafw3232
            </description>
        </channel>
        <channel>
            <category>summer</category>
            
            <date>    
                January 4th 2004
            </date>
            <description>
                dsafasq342zfda
            </description>
        </channel>
        <channel>
            <category>winter</category>
            
            <date>    
                April 4th 2000
            </date>
            <description>
                adsfasdf9890a89ka
            </description>
        </channel>
        <channel>
            <category>spring</category>
            
            <date>    
                May 4th 2004
            </date>
            <description>
                jkdlak9892kahjkd
            </description>
        </channel>
    </rss>

    actionscript:
    PHP Code:
    catarray = new Array();

    for (
    i=0i<totalnumberi++) {
                    for (
    g=0g<totalnumberg++) {
                        if (
    catarray[i] == channels[g].childNodes[0].childNodes[0].nodeValue) {
                                                    
    catarray.splice(i1);
                            
    catarray.push(channels[g].childNodes[0].childNodes[0].nodeValue);
                        } else {
                            
    catarray.push(channels[g].childNodes[0].childNodes[0].nodeValue);
                        }
                                            
                    }
                }
                for (
    t=0t<totalnumbert++) {
                    
    trace(catarray[t]);
                } 
    Ok so heres the issue.... I am pulling from an xml file which has various entries many of them have repeated categories of summer,winter,spring,fall.

    I would like to create a new array which will only hold the unique list of summer,winter,spring,fall. none of which repeat.

    so i should end up with an catarray.length=4 (even if the xml has >4 items ).

    I hope thats' easily understood. Thanx to all in advance

    Cheers,
    ..,,;:'""':;,,..ASTRO

  2. #2
    Denied ACCESSORIES
    Join Date
    Dec 2000
    Location
    Rio de Janeiro
    Posts
    208
    ok never mind I got it figured ... cheers
    ..,,;:'""':;,,..ASTRO

  3. #3
    Member
    Join Date
    Aug 2000
    Posts
    67
    I see this post is about a year old, but it's exactly what I'm looking for. Could you share the answer? Or anyone who may see this.

    Thanks
    -M-

  4. #4
    Denied ACCESSORIES
    Join Date
    Dec 2000
    Location
    Rio de Janeiro
    Posts
    208
    I don't remember exactly what I did but you could easily parse this by looping through the categories. As you create your array from the xml also create a memory array which you will loop through to compair if that category has already been selected. something like this:
    PHP Code:
    var aMemory:Array= [];
    var 
    aCategories:Array=[];
    var 
    aCatTotal:Number=xml.childnodes.length;
    for (var 
    i=0;i<aCatTotal; ++i){
      if(
    i==0){//don't bother checking yet
    aCategories.push(xml[i].node.value);
    aMemory.push(xml[i].node.value);
    }else{
    //check against current array
    var found:Boolean=false;
    var 
    tMemory:Number=aMemory.length;
    for (var 
    g=0g<tMemory; ++g){
    if (
    aMemory[g]==xml[i].node.value){
    //found identical in memory so break
    break;
    }else{
    //none found in memory so add
    aCategories.push(xml[i].node.value);
    aMemory.push(xml[i].node.value);

    }
    }
    }


    Thats the first thing of the top of my head you should be able to build of that. remember that if you want to later access any particular node you can also store its index value in your array so Spring may have two categories and may be stored as [[summer,[0]],[spring,[1,5,6],[fall,[2,3]]....etc....(so instead of just breaking you would add another index number for reference).

    Hope that helps... p.s. not by a computer and the code above is to guide you & most of it is incorrectly referenced.
    ..,,;:'""':;,,..ASTRO

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center