actionscript 3 - Alternative way to rearrange objects on a stage? -
i want menu appear above else when game opens @ minute, menu on top @ first until timer starts of other objects appear on top of menu. how can change menu on top , game starts playing , timer starts once user clicks 'play' button , takes them game?
here code have in main.as file. have been experimenting no avail have tried figure out easiest or efficient way this, frustrated @ minute:
package { import flash.display.movieclip; import flash.events.event; import flash.events.mouseevent; import flash.events.timerevent; import flash.utils.timer; import flash.ui.mouse; import flash.media.sound; import flash.media.soundchannel; import flash.text.textformat; import flash.text.textfield; import flash.display.loader; import flash.net.urlrequest; import flash.net.urlloader; import flash.system.loadercontext; public class main extends movieclip { public var gametime:int; public var levelduration:int; public var crosshair:crosshair_mc; static var score:number; var enemyshiptimer:timer; var enemyshiptimermed:timer; var enemyshiptimersmall:timer; var menu:menumain = new menumain; static var scoreheader:textfield = new textfield(); static var scoretext:textfield = new textfield(); static var timeheader:textfield = new textfield(); static var timetext:textfield = new textfield(); public function main() { levelduration = 30; gametime = levelduration; var gametimer:timer = new timer(1000,levelduration); gametimer.addeventlistener(timerevent.timer, updatetime); gametimer.addeventlistener(timerevent.timer_complete, timeexpired) gametimer.start(); scoreheader = new textfield(); scoreheader.x = 5; scoreheader.text = string("score: "); addchild(scoreheader); scoretext = new textfield(); scoretext.x = 75; scoretext.y = 0; scoretext.text = string(0); addchild(scoretext); timeheader = new textfield(); timeheader.x = 490; timeheader.y = 0; timeheader.text = string("time: "); addchild(timeheader); timetext = new textfield(); timetext.x = 550; timetext.y = 0; timetext.text = gametime.tostring(); addchild(timetext); var scoreformat = new textformat("arial rounded mt bold", 20, 0xffffff); scoreheader.settextformat(scoreformat); scoretext.settextformat(scoreformat); timeheader.settextformat(scoreformat); timetext.settextformat(scoreformat); enemyshiptimer = new timer(2000); enemyshiptimer.addeventlistener("timer", sendenemy); enemyshiptimer.start(); enemyshiptimermed = new timer(2500); enemyshiptimermed.addeventlistener("timer", sendenemymed); enemyshiptimermed.start(); enemyshiptimersmall = new timer(2750); enemyshiptimersmall.addeventlistener("timer", sendenemysmall); enemyshiptimersmall.start(); crosshair = new crosshair_mc(); addchild(crosshair); crosshair.mouseenabled = crosshair.mousechildren = false; mouse.hide(); stage.addeventlistener(event.enter_frame, movecursor); resetscore(); showmenu(); } function showmenu() { stage.addchild(menu); mouse.show(); enemyshiptimer.stop(); enemyshiptimermed.stop(); enemyshiptimersmall.stop(); } function sendenemy(e:event) { var enemy = new enemyship(); stage.addchild(enemy); stage.addchild(crosshair); } function sendenemymed(e:event) { var enemymed = new enemyshipmed(); stage.addchild(enemymed); stage.addchild(crosshair); } function sendenemysmall(e:event) { var enemysmall = new enemyshipsmall(); stage.addchild(enemysmall); stage.addchild(crosshair); } static function updatescore(points) { score += points; scoretext.text = string(score); var scoreformat = new textformat("arial rounded mt bold", 20, 0xffffff); scoreheader.settextformat(scoreformat); scoretext.settextformat(scoreformat); } static function resetscore() { score = 0; scoretext.text = string(score); } function updatetime(e:timerevent):void { trace(gametime); // class variable tracking each second, gametime--; //update user interface needed var scoreformat = new textformat("arial rounded mt bold", 20, 0xffffff); timetext.defaulttextformat = scoreformat; timetext.text = string(gametime); } function timeexpired(e:timerevent):void { var gametimer:timer = e.target timer; gametimer.removeeventlistener(timerevent.timer, updatetime) gametimer.removeeventlistener(timerevent.timer, timeexpired) // whatever need game on } function movecursor(event:event) { crosshair.x=mousex; crosshair.y=mousey; } } }
i have been trying figure out of day don't have lot of experience actionscript.
create 2 containers (sprites or movieclips), add 1 want in first, , 1 want in front second. now, add menu front 1 , evrything else one.
Comments
Post a Comment