这是用鼠标滚轮做到这一点的一种方法:
stage.addEventListener(MouseEvent.MOUSE_WHEEL, zoom);
function zoom(e:MouseEvent) {
square.z+=20*e.delta;
}
你将如何使用KEY_UP和KEY_DOWN进行操作?
stage.addEventListener(KeyboardEvent.KEY_DOWN, zoom);
stage.addEventListener(KeyboardEvent.KEY_UP, zoom);
function zoom(e:MouseEvent):void{
}
答案 0 :(得分:1)
啊,不,这个不会起作用
释放按下的键时会触发KEY_UP。它可以是任何关键。 类似地,按下键时的KEY_DOWN
你真正需要做的事情:
//add event handler for key release
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
//Key release event handler
function keyUpHandler(e:KeyboardEvent):void {
if(e.keyCode==Keyboard.UP) { //up key is pressed
zoomIn();
} else if(e.keyCode==Keyboard.DOWN) { //down key is pressed
zoomOut();
}
}
function zoomIn():void{
square.z+=5;
}
function zoomOut():void{
square.z-=5;
}
答案 1 :(得分:0)
我认为这个会奏效:
stage.addEventListener(KeyboardEvent.KEY_DOWN, zoomIn);
stage.addEventListener(KeyboardEvent.KEY_UP, zoomOut);
function zoomIn(e:MouseEvent):void{
square.z+=5;
}
function zoomOut(e:MouseEvent):void{
square.z-=5;
}