0

Here is my problem. The photography data loads from the XML file. When the user clicks the button that information is overwritten an replaced by the names of all the users in the XML file. What I want to do is when a user clicks on one of the photography buttons ie. landscape that will then only show the names of the people in the XML file with landscape in the profile in the XML.

What is the best way to go about this? Should I try to write an if statement that tells me if the child is found within the XML profile then return the name if the answer is yes? That is what I have been trying to do but not succeeding. Any feedback would be great. Thanks.

photographylist: which contains an array with the duplicates removed from the XML

var photographylist:Array = [];
    xmlinfo.profile.photography.(photographylist.push(toString())); 



for (var i:int =0; i<totalimage; i++){

textvar.text = photographylist[i];    
background.addChild(textvar).addEventListener(MouseEvent.CLICK,loadnames);
            }


               var list2:Array = new Array();
                xmlinfo.profile.first_name.(list2.push(toString())); 
                list2.sort();
                trace(list2 + " array 2 list");

Here is a sample of the XML

<profile>   

        <first_name>ann</first_name>
        <last_name> lee</last_name>
        <photography>sport</photography>
        <photography>landscape</photography>
        <photography>still life</photography>           
        <image>img1.jpg</image>
        <course>multimedia</course>
        <email>annlee@mycit.ie</email>
</profile>
caribou
  • 53
  • 5
  • Hi LDSMS. No I couldn't get it working. Have just come back to it. I changed it to the original code so photographylist is an array of all instances of in the XML splicing out the duplicates. How does the syntax change for my XMLList or can I still use EX4 filtering? – caribou May 23 '15 at 16:35
  • You can only use E4X on XML. Using an array you just have loop through it check each element for the desired value. – BadFeelingAboutThis May 23 '15 at 23:55

1 Answers1

0

Using E4X Filtering, you can get a list of all profiles that have the text landscape in a photograhy node.

var list:XMLList = xmlinfo.profile.(photography.children().contains("landscape"));

//trace out all the names of the matches
for(var i:int=0;i<list.length();i++){
    trace(list[i].first_name.text() + " " + list[i].last_name.text());
}

EDIT

Using an array, you just need to loop through the array and check for the desired value. Here is a helper function that could do that:

var matchingItems:Array = getMatchingItems("landscape");

function getMatchingItems(str:String):Array {
    var results:Array = [];
    for each(var item:String in photographyList){
        if(item == str) results.push(item);
        //or, if you want to see if it contains the text (instead of an exact match)
        if(item.indexOf(str) > -1) results.push(item);

        //use toUpperCase() on both strings if you want non-case sensitive
    }
    return results
} 
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40