キーイベントがアタッチされているときに、actionscript 3 を使用してフラッシュでボタンをアニメーション化する方法を知りたいと思っていました。マウス クリック イベントを使用してボタンの形状を変更する簡単なアニメーションを実行できます (ボタンをダブルクリックして、上、上、下の変更を作成する場合)。その機能はありますが、アニメーションはありません...キーイベントをアニメーション化する方法について誰か考えがありますか?
//initialise variables with functions
var mySound:Sound = new Sound();
mySound.load(new URLRequest("acapella.mp3"));
var myChannel:SoundChannel = new SoundChannel();
clicktoplaymusic.addEventListener(MouseEvent.CLICK, playSound);
function playSound(event:MouseEvent):void
{
myChannel = mySound.play();
}
pausebutton.addEventListener(MouseEvent.CLICK, stopSound);
function stopSound(event:MouseEvent):void
{
myChannel.stop();
}
// The array now holds the drum button objects, the filename, and the corresponding keys.
var soundArray:Array = [
{ "btn": butt1, "file": 't.mp3', "key": 84 },
{ "btn": butt2, "file": 'r.mp3', "key": 82 },
{ "btn": butt3, "file": 'p.mp3', "key": 80 },
{ "btn": butt4, "file": 'o.mp3', "key": 79 },
{ "btn": butt5, "file": 'e.mp3', "key": 69 },
{ "btn": butt6, "file": 'i.mp3', "key": 73 },
{ "btn": butt7, "file": 'u.mp3', "key": 85 },
{ "btn": butt8, "file": 'w.mp3', "key": 87 },
{ "btn": butt9, "file": 'y.mp3', "key": 89 },
{ "btn": butt10, "file": 'q.mp3', "key": 81 } ];
//This adds the mouse click event to the buttons.
for each (var item:Object in soundArray)
{
item.btn.addEventListener(MouseEvent.CLICK, buttonClicked);
}
// This was registered to a button. It needs to be on the stage.;
stage.addEventListener(KeyboardEvent.KEY_DOWN, tsymbolkeyhit);
function tsymbolkeyhit(e:KeyboardEvent):void
{
// Handles playing the sound when hitting keyboard buttons.
for each (var item:Object in soundArray)
{
// If the key we hit matches the keystroke in the array, play the appropriate sound, and break the loop.
if (item.key == e.keyCode)
{
playKey(item.file);
break;
}
}
}
function buttonClicked(e:MouseEvent):void
{
// Handles playing sound when hitting onscreen buttons.
for each (var item:Object in soundArray)
{
// If the button we clicked matches the button in the array, play the appropriate sound, and break the loop.
if (item.btn == e.currentTarget)
{
playKey(item.file);
break;
}
}
}
function playKey(filePath:String):void
{
//plays my specified file.
var snd:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
snd.load(new URLRequest(filePath));
channel = snd.play();
}
// Replaces my mouse with Drumsticks.
stage.addEventListener(Event.ENTER_FRAME, MoveMouse);
Mouse.hide();
function MoveMouse(Event)
{
drum_stick.x = mouseX;
drum_stick.y = mouseY;
}