我用adobe动画制作了一个简单的钢琴,它是由白色和黑色矩形组成的按钮,每个按钮在单击时都有一个音符,它会播放(音频文件设置在向下的关键帧上)注意,我希望能够通过按键盘上的某些键来播放这些注释,这有什么代码吗? 非常感谢!
答案 0 :(得分:1)
您可以在Keyboard events的帮助下实现这一目标。
每个密钥都有一个与之关联的密钥代码。设置示例如下:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
function keyDownHandler(event:KeyboardEvent) :void
{
trace("keyDownHandler: " + event.keyCode); //# is key-code of key pressed down
if (event.keyCode == XXX) //# where XXX is the key-code of pressed key
{
//# put your code here to play the sound for that key
}
}
function keyUpHandler(event:KeyboardEvent) :void
{
trace("keyUpHandler: " + event.keyCode); //# is key-code of key released
}