AS3.0新手问题【访问可能未定义的属性 x y】
varleftArrow:Boolean=false;varrightArrow:Boolean=false;varupArrow:Boolean=false;vardo...
var leftArrow:Boolean=false;
var rightArrow:Boolean=false;
var upArrow:Boolean=false;
var downArrow:Boolean=false;
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressedDown);
stage.addEventListener(KeyboardEvent.KEY_UP,keyPressedUp);
stage.addEventListener(Event.ENTER_FRAME ,moveMascot);
function keyPressedDown(event:KeyboardEvent) {
if (event.keyCode==37) {
leftArrow=true;
} else if (event.keyCode == 39) {
rightArrow=true;
} else if (event.keyCode == 38) {
upArrow=true;
} else if (event.keyCode == 40) {
downArrow=true;
}
}
function keyPressedUp(event:KeyboardEvent) {
if (event.keyCode==37) {
leftArrow=false;
} else if (event.keyCode == 39) {
rightArrow=false;
} else if (event.keyCode == 38) {
upArrow=false;
} else if (event.keyCode == 40) {
downArrow=false;
}
}
function moveMascot(event:Event) {
var speed:Number=5;
if (leftArrow) {
mascot.x-=speed;
}
if (rightArrow) {
mascot.x+=speed;
}
if (upArrow) {
mascot.y-=speed;
}
if (downArrow) {
mascot.y+=speed;
}
}
= = 好像是什么 实例名 链接的什么问题- -我不明白 展开
var rightArrow:Boolean=false;
var upArrow:Boolean=false;
var downArrow:Boolean=false;
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressedDown);
stage.addEventListener(KeyboardEvent.KEY_UP,keyPressedUp);
stage.addEventListener(Event.ENTER_FRAME ,moveMascot);
function keyPressedDown(event:KeyboardEvent) {
if (event.keyCode==37) {
leftArrow=true;
} else if (event.keyCode == 39) {
rightArrow=true;
} else if (event.keyCode == 38) {
upArrow=true;
} else if (event.keyCode == 40) {
downArrow=true;
}
}
function keyPressedUp(event:KeyboardEvent) {
if (event.keyCode==37) {
leftArrow=false;
} else if (event.keyCode == 39) {
rightArrow=false;
} else if (event.keyCode == 38) {
upArrow=false;
} else if (event.keyCode == 40) {
downArrow=false;
}
}
function moveMascot(event:Event) {
var speed:Number=5;
if (leftArrow) {
mascot.x-=speed;
}
if (rightArrow) {
mascot.x+=speed;
}
if (upArrow) {
mascot.y-=speed;
}
if (downArrow) {
mascot.y+=speed;
}
}
= = 好像是什么 实例名 链接的什么问题- -我不明白 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询