Difference between revisions of "AS2 and XML"
From Wikicliki
(→AS2) |
|||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
== XML == | == XML == | ||
+ | <pre> | ||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<entries> | <entries> | ||
Line 47: | Line 48: | ||
== AS2 == | == AS2 == | ||
+ | <pre> | ||
import caurina.transitions.Tweener; | import caurina.transitions.Tweener; | ||
Line 56: | Line 58: | ||
} | } | ||
− | |||
function loadScoreXML() { | function loadScoreXML() { | ||
xmlNode = scoreboardXML.firstChild; | xmlNode = scoreboardXML.firstChild; |
Latest revision as of 09:19, 16 July 2010
This is the full example of how I used AS2 with XML.
XML
<?xml version="1.0" encoding="utf-8"?> <entries> <entry> <id>12</id> <schoolName>SchoolName One</schoolName> <teamName>TEAM RAVEN</teamName> <voteTotalCount>50</voteTotalCount> <ranking>1</ranking> </entry> <entry> <id>11</id> <schoolName>SchoolName Two</schoolName> <teamName>TEAM ALPACA</teamName> <voteTotalCount>40</voteTotalCount> <ranking>2</ranking> </entry> <entry> <id>10</id> <schoolName>SchoolName Three</schoolName> <teamName>TEAM LLAMA</teamName> <voteTotalCount>30</voteTotalCount> <ranking>3</ranking> </entry> <entry> <id>9</id> <schoolName>SchoolName Four</schoolName> <teamName>TEAM HOTDOG</teamName> <voteTotalCount>20</voteTotalCount> <ranking>4</ranking> </entry> <entry> <id>1</id> <schoolName>SchoolName Five</schoolName> <teamName>TEAM HEDGEHOG</teamName> <voteTotalCount>11</voteTotalCount> <ranking>5</ranking> </entry> </entries>
AS2
import caurina.transitions.Tweener; junior_btn.onRelease = function(){ gotoAndPlay("junior"); } senior_btn.onRelease = function(){ gotoAndPlay("senior"); } function loadScoreXML() { xmlNode = scoreboardXML.firstChild; //trace("xmlNode: "+scoreboardXML) entryId = []; schoolName = []; teamName = []; voteNumber = []; ranking = []; total = xmlNode.childNodes.length; for (k=0; k<total; k++) { entryId[k] = xmlNode.childNodes[k].childNodes[0].firstChild.nodeValue; schoolName[k] = xmlNode.childNodes[k].childNodes[1].firstChild.nodeValue; teamName[k] = xmlNode.childNodes[k].childNodes[2].firstChild.nodeValue; voteNumber[k] = xmlNode.childNodes[k].childNodes[3].firstChild.nodeValue; ranking[k] = xmlNode.childNodes[k].childNodes[4].firstChild.nodeValue; } total_txt.text = "total entries: "+total; pencil_01_txt.text = schoolName[0]+" - "+teamName[0]; pencil_02_txt.text = schoolName[1]+" - "+teamName[1]; pencil_03_txt.text = schoolName[2]+" - "+teamName[2]; pencil_04_txt.text = schoolName[3]+" - "+teamName[3]; pencil_05_txt.text = schoolName[4]+" - "+teamName[4]; voteNum1 = voteNumber[0] * 1; voteNum2 = voteNumber[1] * 1; voteNum3 = voteNumber[2] * 1; voteNum4 = voteNumber[3] * 1; voteNum5 = voteNumber[4] * 1; totalVoteNum = voteNum1 + voteNum2 + voteNum3 + voteNum4 + voteNum5; trace(totalVoteNum); percent_01 = Math.round((voteNum1/totalVoteNum)*100); percent_02 = Math.round((voteNum2/totalVoteNum)*100); percent_03 = Math.round((voteNum3/totalVoteNum)*100); percent_04 = Math.round((voteNum4/totalVoteNum)*100); percent_05 = Math.round((voteNum5/totalVoteNum)*100); percent_01_txt.text = percent_01+"%"; percent_02_txt.text = percent_02+"%"; percent_03_txt.text = percent_03+"%"; percent_04_txt.text = percent_04+"%"; percent_05_txt.text = percent_05+"%"; fullPencil = 470; // 788 originalPencil = 381; percent_01_x = originalPencil + percent_01 * fullPencil / 100; percent_02_x = originalPencil + percent_02 * fullPencil / 100; percent_03_x = originalPencil + percent_03 * fullPencil / 100; percent_04_x = originalPencil + percent_04 * fullPencil / 100; percent_05_x = originalPencil + percent_05 * fullPencil / 100; Tweener.addTween(pencilmove1,{_x: percent_01_x, delay:0, time:3, transition:"easeOutExpo"}); Tweener.addTween(pencilmove2,{_x: percent_02_x, delay: 0.2, time:3, transition:"easeOutExpo"}); Tweener.addTween(pencilmove3,{_x: percent_03_x, delay: 0.4, time:3, transition:"easeOutExpo"}); Tweener.addTween(pencilmove4,{_x: percent_04_x, delay: 0.6, time:3, transition:"easeOutExpo"}); Tweener.addTween(pencilmove5,{_x: percent_05_x, delay: 0.8, time:3, transition:"easeOutExpo"}); } function juniorGo(){ scoreboardXML = new XML(); scoreboardXML.ignoreWhite = true; scoreboardXML.onLoad = function(){ //trace("XML LOADED"); loadScoreXML(); } var xmlFileName = "score_junior.xml"; trace("xmlFileName: "+xmlFileName); scoreboardXML.load(xmlFileName); } function seniorGo(){ scoreboardXML = new XML(); scoreboardXML.ignoreWhite = true; scoreboardXML.onLoad = function(){ //trace("XML LOADED"); loadScoreXML(); } var xmlFileName = "score_senior.xml"; trace("xmlFileName: "+xmlFileName); scoreboardXML.load(xmlFileName); } juniorGo();