As I have started development into a new game, and am starting to notice some fundamental benefits of AS3, I would like to invest time to learn how coding works under the setup of the actionscript on the frame rather than inside the movieclip in AS2. I would really appreciate if someone could point out what I am doing wrong! I have tried to port over this code:
onClipEvent (load) {
//variables
var stepnum:Number = 10;
var attack:Boolean = false;
var stance:Number = 1;
var crouch:Boolean = false;
var moving:Boolean = false;
//aiming variables
var aimUp_lower:Number = 10;
var aimDown_neutral:Number = 15;
var aimUp_neutral:Number = 20;
var aimDown_upper:Number = 25;
var aimNeutral:Number = 30;
var aimlevel01:Boolean = false;
var aimlevel0:Boolean = true;
var aimlevel1:Boolean = false;
//Keyboard controls
var DOWN:Number = 40;
var UP:Number = 38;
var LEFT:Number = 37;
var RIGHT:Number = 39;
var SPACE:Number = 32;
}
onClipEvent (enterFrame) {
//movement
if (Key.isDown(RIGHT)) {
this._xscale = 100;
moving = true;
stance = 1;
this._x += stepnum;
this.walkcycle.play();
} else if (Key.isDown(LEFT)) {
this._xscale = -100;
moving = true;
stance = 0;
this._x -= stepnum;
this.walkcycle.play();
} else {
this.walkcycle.gotoAndStop('idle');
}
if (Key.isDown(DOWN)) {
this.aiming.gotoAndStop('aim_down01');
aimlevel1 = false;
aimlevel0 = false;
aimlevel01 = true;
} else if (aimlevel01 && !Key.isDown(DOWN)) {
this.aiming.gotoAndStop('aim_up00');
aimlevel1 = false;
aimlevel0 = true;
aimlevel01 = false;
}
if (Key.isDown(UP)) {
this.aiming.gotoAndStop('aim_up01');
aimlevel1 = true;
aimlevel0 = false;
aimlevel01 = false;
} else if (aimlevel1 && !Key.isDown(UP)) {
this.aiming.gotoAndStop('aim_down00');
aimlevel1 = false;
aimlevel0 = true;
aimlevel01 = false;
}
}
Like this, but the code doesn’t work… I need some help
stop();
function VariableSetup() {
//variables
var stepnum:Number = 10;
var attack:Boolean = false;
var stance:Number = 1;
var crouch:Boolean = false;
var moving:Boolean = false;
//aiming variables
var aimUp_lower:Number = 10;
var aimDown_neutral:Number = 15;
var aimUp_neutral:Number = 20;
var aimDown_upper:Number = 25;
var aimNeutral:Number = 30;
var aimlevel01:Boolean = false;
var aimlevel0:Boolean = true;
var aimlevel1:Boolean = false;
//Keyboard controls
var DOWN:Number = 40;
var UP:Number = 38;
var LEFT:Number = 37;
var RIGHT:Number = 39;
var SPACE:Number = 32;
}
function movement() {
//movement
if (Key.isDown(RIGHT)) {
_root.MasterChief_mc._xscale = 100;
moving = true;
stance = 1;
_root.MasterChief_mc._x += stepnum;
_root.MasterChief_mc.walkcycle.play();
} else if (Key.isDown(LEFT)) {
_root.MasterChief_mc._xscale = -100;
moving = true;
stance = 0;
_root.MasterChief_mc._x -= stepnum;
_root.MasterChief_mc.walkcycle.play();
} else {
_root.MasterChief_mc.walkcycle.gotoAndStop('idle');
}
}
function aiming() {
if (Key.isDown(DOWN)) {
_root.MasterChief_mc.aiming.gotoAndStop('aim_down01');
aimlevel1 = false;
aimlevel0 = false;
aimlevel01 = true;
} else if (aimlevel01 && !Key.isDown(DOWN)) {
_root.MasterChief_mc.aiming.gotoAndStop('aim_up00');
aimlevel1 = false;
aimlevel0 = true;
aimlevel01 = false;
}
if (Key.isDown(UP)) {
_root.MasterChief_mc.aiming.gotoAndStop('aim_up01');
aimlevel1 = true;
aimlevel0 = false;
aimlevel01 = false;
} else if (aimlevel1 && !Key.isDown(UP)) {
_root.MasterChief_mc.aiming.gotoAndStop('aim_down00');
aimlevel1 = false;
aimlevel0 = true;
aimlevel01 = false;
}
}
//Function calls
VariableSetup();
onEnterFrame = function () {
movement();
aiming();
};