I am an ActionScript newbie and so I found a tutorial on kirupa.com for a xml
slide show that I was able to adapt to create a scoreboard for football scores.
Most of it seems to work just fine. When I click the next and previous
buttons, the scores cycle through but when I initially launch, the first score
doesn't display. The tutorial had an image loader to make sure the files had
completely loaded and I had no need for it so I removed that part but evidently
what I removed also helped to display the first node. Any help would be
awesome!
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
team1 = [];
score1 = [];
team2 = [];
score2 = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
team1[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
score1[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
team2[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
score2[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
}
firstMatchup();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("scores.xml");
/////////////////////////////////////
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevMatchup();
} else if (Key.getCode() == Key.RIGHT) {
nextMatchup();
}
};
Key.addListener(listen);
prev_btn.onRelease = function() {
prevMatchup();
};
next_btn.onRelease = function() {
nextMatchup();
};
/////////////////////////////////////
p = 0;
function nextMatchup() {
if (p<(total-1)) {
p++;
team1_txt.text = team1[p];
score1_txt.text = score1[p];
team2_txt.text = team2[p];
score2_txt.text = score2[p];
matchup_num();
}
}
function prevMatchup() {
if (p>0) {
p--;
team1_txt.text = team1[p];
score1_txt.text = score1[p];
team2_txt.text = team2[p];
score2_txt.text = score2[p];
matchup_num();
}
function firstMatchup() {
team1_txt.text = team1[0];
score1_txt.text = score1[0];
team2_txt.text = team2[0];
score2_txt.text = score2[0];
matchup_num();
}
}
function matchup_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}
kglad - 06 Oct 2008 23:43 GMT
why is firstMatchup() nested inside prevMatchup()?