actionscript 3 - How to restart an SWF with a click of a button? -
i have created drag , drop mini-game and, once finished, wish user able click "try again" button , have whole thing start over. have read in , see there couple of options stuck best me. have created fla of library items, file (maingame.as) main game , of it's functions in 1 class , second file (mygame.as) calls class file play game.
which work best me? have nothing on layers , cannot figure out how remove swf , load again click of button. right in thinking add button mygame file in timerdone
function? if so, how use reload swf start?
here timerdone
function ...
function timerdone(e:timerevent=null):void { if (countdown == 0) { count = 0; finalscore = score; } else { count = (30) - (mytimer.currentcount); finalscore = (count * 10) + (score); } mytext.text = "game over!"; mytext.x = 195; displaytext(); mytext2.text = "your score = " + (finalscore); displaytext2(); }
i thinking add button after last line , somehow refresh swf, right? or way off?
you should that: call function toreplay @ end of function timerdone:
function timerdone, after "displaytext2();"
tryagain.addeventlistener(mouseevent.click, toreplay);
outside function timerdone
/** * function toreplay calls function init * initializes timer , variables. **/ function toreplay(e:mouseevent):void { e.target.removeeventlistener(mouseevent.click, toreplay); init(); } function init():void { // timer count = 0; finalscore = 0; mytext.text = ""; // etc. }
and function init can directly invoked initialize variables @ begining of game:
init();
Comments
Post a Comment