Well here is the code all together.
hero.gotoAndStop('still');
var Key:KeyObject = new KeyObject(stage);
var dy:Number = -3;
var gravity:Number = 1;
var canJump:Boolean = false;
stage.addEventListener(Event.ENTER_FRAME,onenter);
function onenter(e:Event) :void{
//Jump
dy+=gravity;
if(hero.y>300){
dy=0;
canJump=true;
}
if(Key.isDown(Key.UP) && canJump) {
dy=-10;
canJump=false;
}
hero.y+=dy;
//Character Movement
if((Key.isDown(Key.DOWN)) && (Key.isDown(Key.A))){
hero.gotoAndStop('Dattack');
}
else if(Key.isDown(Key.RIGHT)){
if (Key.isDown(Key.SHIFT)) {
hero.x+=10;
hero.scaleX=1;
hero.gotoAndStop('run');
}else {
hero.x+=5;
hero.scaleX=1;
hero.gotoAndStop('walk');
}
}else if(Key.isDown(Key.LEFT)){
if (Key.isDown(Key.SHIFT)) {
hero.x-=10;
hero.scaleX=-1;
hero.gotoAndStop('run');
}else {
hero.x-=5;
hero.scaleX=-1;
hero.gotoAndStop('walk');
}
} else if(Key.isDown(Key.A)){
hero.gotoAndStop('attack1');
} else if(Key.isDown(Key.S)){
hero.gotoAndStop('attack2');
} else if(Key.isDown(Key.DOWN)){
hero.gotoAndStop('duck');
} else{
hero.gotoAndStop('still');
}if (hero.y < 300)//Air Movement
{
if (Key.isDown(Key.A))
{
hero.gotoAndStop('attack1');
}
else if (Key.isDown(Key.S)){
hero.gotoAndStop.('attack2');
}else
{
hero.gotoAndStop('jumping');
}
}
}
hero.gotoAndStop('still');
var Key:KeyObject = new KeyObject(stage);
var dy:Number = -3;
var gravity:Number = 1;
var canJump:Boolean = false;
stage.addEventListener(Event.ENTER_FRAME,onenter);
function onenter(e:Event) :void{
//Jump
dy+=gravity;
if(hero.y>300){
dy=0;
canJump=true;
}
if(Key.isDown(Key.UP) && canJump) {
dy=-10;
canJump=false;
}
hero.y+=dy;
//Character Movement
if((Key.isDown(Key.DOWN)) && (Key.isDown(Key.A))){
hero.gotoAndStop('Dattack');
}
else if(Key.isDown(Key.RIGHT)){
if (Key.isDown(Key.SHIFT)) {
hero.x+=10;
hero.scaleX=1;
hero.gotoAndStop('run');
}else {
hero.x+=5;
hero.scaleX=1;
hero.gotoAndStop('walk');
}
}else if(Key.isDown(Key.LEFT)){
if (Key.isDown(Key.SHIFT)) {
hero.x-=10;
hero.scaleX=-1;
hero.gotoAndStop('run');
}else {
hero.x-=5;
hero.scaleX=-1;
hero.gotoAndStop('walk');
}
} else if(Key.isDown(Key.A)){
hero.gotoAndStop('attack1');
} else if(Key.isDown(Key.S)){
hero.gotoAndStop('attack2');
} else if(Key.isDown(Key.DOWN)){
hero.gotoAndStop('duck');
} else{
hero.gotoAndStop('still');
}if (hero.y < 300)//Air Movement
{
if (Key.isDown(Key.A))
{
hero.gotoAndStop('attack1');
}
else if (Key.isDown(Key.S)){
hero.gotoAndStop.('attack2');
}else
{
hero.gotoAndStop('jumping');
}
}
}