Hi KirupaPeople!
I’ve created a simple flash movie that pulls search results from an xml file generated by php from an sql database.
I’ve created a for loop that goes through each of the results and displays their attributes, e.g. an image, their username and a location. Now each user also has a unique ID that i would like to use to link to a unique page showing more of their details.
Now this loop works perfectly fine showing each users details in succession, except that when i use an onRelease action on the search result, to send the user to the unique page and forward the ID variable, it always returns the ID variable of the last item in the list, no matter which item i click on.
can’t figure out for the life of me why this should be so because all the other variables are pulled out fine from the xml file.
My code is as below.
var searchXML:XML = new XML();
searchXML.ignoreWhite = true;
searchXML.onLoad = function() {
//show user search terms
resultsheader_txt.text = "Search Results: you searched for '"+_root.searchterm+"' in "+_root.searchcriteria+".";
//create array from XML
var resultsList:Array = this.firstChild.childNodes;
//set spacing between results
var spacing:Number = 100;
//cycle through results
for (i=0; i<resultsList.length; i++) {
itemEntry = resultsList*.attributes;
//trace(i+itemEntry.username);
//create mc for each result
resultHolder = searchresults_mc.createEmptyMovieClip("result"+i, i);
//set spacing
resultHolder._y = i*spacing;
//create mc for userimage & load image
thumbLoader = resultHolder.createEmptyMovieClip("result_image", i+1);
thumbLoader.loadMovie("userimages/"+itemEntry.image);
//create text fields for username & location
resultHolder.createTextField("username_txt", this.getNextHighestDepth(), 100, 10, 150, 30);
resultHolder.createTextField("location_txt", this.getNextHighestDepth()-1000, 100, 30, 150, 30);
//fill textfields & format
resultHolder.username_txt.text = itemEntry.username;
resultHolder.username_txt.setTextFormat(username_fmt);
resultHolder.location_txt.text = itemEntry.location;
resultHolder.location_txt.setTextFormat(location_fmt);
//set userID and send to viewprofile page
resultHolder.onRelease = function() {
trace(itemEntry.userID);
_root.viewUser = itemEntry.userID;
_root.gotoAndPlay("viewprofile");
};
}
play();
};
The problem is within the onRelease action as if i replace the
resultHolder.onRelease = function() {
trace(itemEntry.userID);
}
code with
resultHolder.onRelease = function() {
trace(itemEntry.username);
or any other attribute it still outputs the last item in the list.
Many thanks in advance for your help!