So far in my studies, I have learnt to write in numerous programming languages, such as: Turbo Pascal, Visual Basic, C++ and even Java. The problem was, when I start learning the language I could eventually write it and speak it fluently as if it were my second language. But once I stopped practicing it, I ended up forgetting how to even define the simplest of things like variables.
So today we had some basic code broken down to us. I found quite thorny to wade my way through all the lines, I figured out what the line was doing more or less, I just couldn’t understand the lingo. I eventually managed to work through the code to understand its core task, all it was simply doing was listening out for any key presses and then taking the user back/forth to the next screen.
// set up
fscommand2("FullScreen", "true");
status = fscommand2("SetSoftKeys", "left", "right");
doStart();
// trap key presses
var globalKeyListener:Object = new Object();
globalKeyListener.onKeyDown = trapKeyDown;
function trapKeyDown():Void {
var keyCode = Key.getCode();
var theFrame = _currentFrame;
trace(keyCode +" / "+theFrame);
switch (keyCode) {
case ExtendedKey.SOFT1 :
switch (theFrame) {
case 2 :
doGame();
break;
case 3 :
doStart();
break;
case 4 :
doStart();
break;
case 5 :
doStart();
}
break;
case ExtendedKey.SOFT2 :
switch (theFrame) {
case 2 :
doExit();
break;
case 3 :
doExit();
break;
case 4 :
doBye();
break;
}
}
}
Key.addListener(globalKeyListener);
function doStart():Void {
gotoAndStop("start");
trace("doStart");
}
function doGame():Void {
gotoAndStop("game");
trace("doGame");
}
function doExit():Void {
gotoAndStop("exit");
trace("doExit");
}
function doBye():Void {
gotoAndStop("bye");
trace ("doBye");
}
No comments:
Post a Comment