Hi all can you pleae help with a problem. I have followed this tutorial and have got it working, i have changed a few things so i can make use of it on my webpage.
http://www.kirupa.com/web/xml/examples/sortedgradeslist.htm
It all works, the data is loaded correctley into the right coulmns and the first 3 columns sort.
The only thing im stuck on is getting my last 2 cloumns to sort :sad:
You can view the page here : http://www.theoaps.co.uk/Support%20Files/OLAN31307PSBF22.swf
Action Script :
PopulateLists = function(xml_array){
name_txt.text = teamscore_txt.text = kills_txt.text = deaths_txt.text = score_tx.text = "";
for (var i=0; i<xml_array.length; i++){
var student = xml_array*.attributes;
name_txt.text += student.first + "
";
teamscore_txt.text += student.teamscore + "
";
kills_txt.text += student.kills + "
";
death_txt.text += student.deaths + "
";
score_txt.text += student.score + "
";
}
}
var students_array;
var grades_xml = new XML();
grades_xml.ignoreWhite = true;
grades_xml.onLoad = function(success){
if (success){
var grades = this.firstChild;
students_array = grades.childNodes;
PopulateLists(students_array);
}else trace("Error loading XML file.");
}
grades_xml.load("olan31307.xml");
FIRST_SORT = function(a,b){
return a.attributes.first > b.attributes.first;
}
TSCORE_SORT = function(a,b){
return parseFloat(a.attributes.teamscore) < parseFloat(b.attributes.teamscore);
}
KILL_SORT = function(a,b){
return parseFloat(a.attributes.kills) < parseFloat(b.attributes.kills);
}
DEATH_SORT = function(a,b){
return parseFloat(a.attributes.deaths) < parseFloat(b.attributes.deaths);
}
OSCORE_SORT = function(a,b){
return parseFloat(a.attributes.oscore) < parseFloat(b.attributes.oscore);
}
var current_sort;
SortListBy = function(sortType){
if (current_sort == sortType){
students_array.reverse();
}else{
students_array.sort(sortType);
}
current_sort = sortType;
PopulateLists(students_array);
}
name_btn.onRelease = function(){
SortListBy(FIRST_SORT);
}
tscore_btn.onRelease = function(){
SortListBy(TSCORE_SORT);
}
kill_btn.onRelease = function(){
SortListBy(KILL_SORT);
}
death_btn.onRelease = function(){
SortListBy(DEATH_SORT);
}
oscore_btn.onRelease = function(){
SortListBy(OSCORE_SORT);
}
.xml Data :
<?xml version="1.0" ?>
<olan date="31307">
<player first="Dunkyb123" teamscore="10" kills="1" deaths="2" score="28" />
<player first="Captain Sausage" teamscore="30" kills="19" deaths="4" score="24" />
<player first="Fat Pants" teamscore="8" kills="18" deaths="6" score="20" />
<player first="Hammer66" teamscore="7" kills="17" deaths="8" score="16" />
<player first="Woolmer" teamscore="6" kills="16" deaths="10" score="12" />
<player first="Discotoe" teamscore="5" kills="15" deaths="12" score="8" />
<player first="Tammyb" teamscore="4" kills="14" deaths="14" score="4" />
<player first="Angrytoad" teamscore="3" kills="13" deaths="16" score="0" />
<player first="Starman_uk8" teamscore="2" kills="12" deaths="18" score="-4" />
<player first="Ianuk" teamscore="1" kills="11" deaths="20" score="-8" />
<player first="Beaver44" teamscore="2" kills="10" deaths="22" score="-10" />
<player first="Rogue Spear" teamscore="3" kills="9" deaths="24" score="-12" />
<player first="TrooperTooke" teamscore="4" kills="8" deaths="26" score="-14" />
</olan>
Please help i have been stuck on this for weeks :sad:
Thanks
Dunkyb123