actionscript 3 - Game doesn't play on second frame -
i'm trying work on game, college assignment. i'm using flash , actionscript 3 (i'm using older version of flash, 2015 version, when still called adobe flash). when placing code within first frame, player object movement works fine, when place in second frame, not work. why? code same! , think more convenient if had gameplay start frame 2 (at least have first level held @ frame). @ frame 1, want have main menu. so, here code have @ frame 1:
import flash.display.movieclip; import flash.events.event; stop(); var optionsactive:boolean = false; var gamepaused:boolean = false; startgame(); function startgame():void { if (optionsactive == false) { optionsui.visible = false; } else { optionsui.visible = true; } menutextoptions_active.addeventlistener(mouseevent.click, activatemenuoptions); menutextnewgame_active.addeventlistener(mouseevent.click, activatestartnewgame); } function activatestartnewgame(event:event) { gotoandstop(2); } function activatemenuoptions(event:event) { optionsactive = true; optionsui.visible = true; if (this.currentframe == 1) { if (menutextcontinue_active.visible != false) { menutextcontinue_active.visible = false; } if (menutextnewgame_active.visible != false) { menutextnewgame_active.visible = false; } if (menutextoptions_active.visible != false) { menutextoptions_active.visible = false; } if (menutextexitgame_active.visible != false) { menutextexitgame_active.visible = false; } if (menubutton_continue.visible != false) { menubutton_continue.visible = false; } if (menubutton_newgame.visible != false) { menubutton_newgame.visible = false; } if (menubutton_options.visible != false) { menubutton_options.visible = false; } if (menubutton_exitgame.visible != false) { menubutton_exitgame.visible = false; } } }
and here's code have @ frame 2:
import flash.display.movieclip; import flash.events.event; stop(); var keybaordleft:int = 37; var keyboardup:int = 38; var keyboardright:int = 39; var keyboarddown:int = 40; var playerxspeed:int = 4; var playeryspeed:int = 4; var leftdown:boolean = false; var updown:boolean = false; var rightdown:boolean = false; var downdown:boolean = false; optionsactive = false; gamepaused = false; startlevel(); function startlevel():void { if (optionsactive == false) { optionsui.visible = false; } else { optionsui.visible = true; } stage.addeventlistener(mouseevent.click, activatemenuoptions); mc_playership.addeventlistener(event.enter_frame, moveplayer); stage.addeventlistener(keyboardevent.key_down, checkkeysdown); stage.addeventlistener(keyboardevent.key_up, checkkeysup); } function checkkeysdown(event:keyboardevent):void { if (event.keycode == 37) { leftdown=true; } if (event.keycode == 38) { updown=true; } if (event.keycode == 39) { rightdown=true; } if (event.keycode == 40) { downdown=true; } } function checkkeysup(event:keyboardevent):void { if (event.keycode == 37) { leftdown=false; } if (event.keycode == 38) { updown=false; } if (event.keycode == 39) { rightdown=false; } if (event.keycode == 40) { downdown=false; } } function moveplayer(event:event):void { if (leftdown) { mc_playership.x -= playerxspeed; } if (updown) { mc_playership.y -= playeryspeed; } if (rightdown) { mc_playership.x += playerxspeed; } if (downdown) { mc_playership.y += playeryspeed; } }
and character not move @ all. why , how fix it?
this not answer question may still helpful.
if (this.currentframe == 1) { if (menutextcontinue_active.visible != false) { menutextcontinue_active.visible = false; } if (menutextnewgame_active.visible != false) { menutextnewgame_active.visible = false; } if (menutextoptions_active.visible != false) { menutextoptions_active.visible = false; } if (menutextexitgame_active.visible != false) { menutextexitgame_active.visible = false; } if (menubutton_continue.visible != false) { menubutton_continue.visible = false; } if (menubutton_newgame.visible != false) { menubutton_newgame.visible = false; } if (menubutton_options.visible != false) { menubutton_options.visible = false; } if (menubutton_exitgame.visible != false) { menubutton_exitgame.visible = false; } }
can replaced this:
if (this.currentframe == 1){ if (uielements.visible != false){ uielements.visible = false; } }
if put buttons , movie clips 1 parent container called uielements
.
edit 11-12-16
first make sure import flash.display.*
to create container outside function:
var uielements:sprite = new sprite(); // creates instance of sprite class
(a sprite same movie clip has no timeline of own, takes less memory)
then in main constructor do:
addchild(uielements); // adds sprite stage
then, wherever create elements want add container do:
uielements.addchild(yournewmchere); //this adds other movie clip container
does make sense?
so that's programmatic way it. if creating elements in ide, can creating empty movieclip , adding other movie lips (like select movieclip, ctrl+x cut, double click movie clip want use container, ctrl+v paste, repeat movie clips want add container. same thing have shown programmatically).
Comments
Post a Comment