AS3 Help! Dynamic XML Loop w/ Next/Prev functionality
hello,
i'm working on pick'em game uses xml load data. have menu (function weekmatchup) shows games of week, , matchup make pick (function showgame).
i'm trying next , forward buttons control arrays in showgame. want user have ability directly select game want pick on top menu. created loaddata function (which modification display items similar showgame) works next/prev buttons.
i tried putting function showgame in loaddata function, , use matchup_array in nextgame function. however, whenever excute error #1034
type coercion failed: cannot convert gamematchup flash.display.loader
at nextgame()
any appreciated
here's code:
function weekmatchups():void { addchild(weekcontainer); // ** create games of week menu buttons (i = 0; < totalgames; i++) { butn = new menubutton(); butn.x = * 47; butn.gamenum = i; //butn.name = "mc_butn"+(i+1); butn.buttonmode = true; butn.matchupaway_txt.mouseenabled = false; butn.matchupaway_txt.text = game[i].team[1].initial; butn.matchuphome_txt.mouseenabled = false; butn.matchuphome_txt.text = game[i].team[0].initial; var iconaway:loader = new loader(); iconaway.load(new urlrequest("images/" + game[i].team[1].icon)); iconaway.contentloaderinfo.addeventlistener(event.complete, oncomplete); butn.iconaway_mc.addchild(iconaway); var iconhome:loader = new loader(); iconhome.load(new urlrequest("images/" + game[i].team[0].icon)); butn.iconhome_mc.addchild(iconhome); butn_array.push(butn); weekcontainer.addchild(butn); butn.addeventlistener(mouseevent.click, showgame); //butn.addeventlistener(mouseevent.click, thumb_handler); if(i==0){ addborder(butn); } } weekcontainer.x = math.round((stage.stagewidth/2) - ((weekcontainer.width-45)/2)); } function loaddata():void{ // load team helmets (i = 0; < temp_array.length; i++){ gamethumb.removechild(temp_array[i]); } temp_array = []; (var h:number = 0; h < totalgames; h++){ var homehelmet:string = game[h].team[0].img; var loadhomehelmet:loader = new loader(); loadhomehelmet.load(new urlrequest("images/" + homehelmet)); loadhomehelmet.contentloaderinfo.addeventlistener(event.complete, oncomplete); loadhomehelmet_array.push(loadhomehelmet); loadhomehelmet.addeventlistener(mouseevent.click, gamepick); } (var a:number = 0; < totalgames; a++){ var awayhelmet:string = game[a].team[1].img; var loadawayhelmet:loader = new loader(); loadawayhelmet.load(new urlrequest("images/" + awayhelmet)); loadawayhelmet.contentloaderinfo.addeventlistener(event.complete, oncomplete); loadawayhelmet_array.push(loadawayhelmet); } } function showgame(event:event):void { addchild(gamecontainer); trace("game " + event.currenttarget.gamenum + " clicked"); // ** click on main button; create second set of buttons right; make sure // remove buttons created (i = 0; < matchup_array.length; i++) { gamecontainer.removechild(matchup_array[i]); //matchupwinner.visible = false; //temporary !!!!! } matchup_array = []; (i = 0; < game[event.currenttarget.gamenum].team.length(); i++) { //gamecontainer.home_txt.text = xmldata.matchup.game[event.currenttarget.num].team.@name; //gamecontainer.away_txt.text = xmldata.matchup.game[event.currenttarget.num].team.@name; matchup = new gamematchup(); //matchups.push(matchup); matchup.y = 0; matchup.x = * 425; matchup.supnum = event.currenttarget.gamenum; matchup.num = i; matchup.name = "mc_matchup"+(i+1); // let mouse ignore text field whole button clickable matchup.team_txt.mouseenabled = false; matchup.team_txt.text = game[event.currenttarget.gamenum].team[i].city; trace(game[event.currenttarget.gamenum].team[i].img); var imgloader:loader = new loader(); //imgloader = new teamhelmet(); imgloader.load(new urlrequest("images/" + game[event.currenttarget.gamenum].team[i].img)); matchup.helmet_mc.addchild(imgloader); //matchup.helmet_mc = xmldata.matchup.game[event.currenttarget.num].team[i].img; matchup.buttonmode = true; matchup_array.push(matchup); matchup.addeventlistener(mouseevent.click, gamepick); gamecontainer.addchild(matchup); //matchup.addeventlistener(mouseevent.click, highlightmenu); } gamecontainer.x = math.round((stage.stagewidth/2) - ((gamecontainer.width)/2)); } function oncomplete(event:event):void{ successcounter++; if (successcounter == totalgames){ startgame(); } } function startgame():void{ addchild(matchupcontainer); matchupcontainer.addchild(gamethumb); gamethumb.addchild(gamecontainer); hometext.selectable=false; hometext.x = 25; hometext.y = 200; addchild(hometext); awaytext.selectable=false; awaytext.x = 725; awaytext.y = 200; addchild(awaytext); nextgame(); } function nextgame():void{ var homehelmet:loader = loader(loadhomehelmet_array[currentgame]); gamethumb.addchild(homehelmet); homehelmet.x = 0; homehelmet.y = 0; var awayhelmet:loader = loader(loadawayhelmet_array[currentgame]); gamethumb.addchild(awayhelmet); awayhelmet.x = 325; awayhelmet.y = 0; matchupcontainer.x = (stage.stagewidth - matchupcontainer.width)/2; matchupcontainer.y = 75; if(selectedborder){ selectedborder.parent.filters = new array(); selectedborder.parent.removechild(selectedborder); } addborder(butn_array[currentgame]); hometext.text = game[currentgame].team[0].city; awaytext.text = game[currentgame].team[1].city; } var selectedborder:movieclip; function addborder(mymc):void{ var mc:movieclip = new movieclip(); mc.graphics.linestyle(3, 0x005ce7) mc.graphics.drawrect(-23, 0, 45, 40); mc.graphics.endfill(); mymc.addchild(mc); selectedborder = mc; } function prevbtn(event:mouseevent):void{ if (currentgame <=0){ currentgame = totalgames -1; }else{ currentgame--; } nextgame(); } function nextbtn(event:mouseevent):void{ if (currentgame >= totalgames -1){ currentgame = 0; }else{ currentgame++; } nextgame(); }
you're declaring gamematchup() class. should post code too. stands seems class not same class type need complete application process. may able cast variable different type i'm not sure. expert need weigh in. post code gamematchup().
More discussions in ActionScript 3
adobe
Comments
Post a Comment