Hi all, I am new to kirupa and new to as3! I’m trying to control my mp3 sound clips with keyboard commands and have managed to get this to work with internal sound clips:
//***************************************************************
var note2:b = new b();
btn2.addEventListener(MouseEvent.MOUSE_DOWN,playNote2);
function playNote2(event:Event){
playSound(note2);
}
function playSound2(soundObject:Object) {
var channel:SoundChannel = soundObject.play();
}
//***************************************************************
//btn2
btn2.addEventListener(MouseEvent.MOUSE_UP, bOut2);
btn2.addEventListener(MouseEvent.MOUSE_DOWN, bDown2);
function bDown2(event:MouseEvent):void {
btn2.gotoAndStop(2);
}
function bOut2(event:MouseEvent):void {
btn2.gotoAndStop(1);
}
btn2.buttonMode = true
//keyboard*****************************************************
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown2);
function myKeyDown2(e:KeyboardEvent):void{
if (e.keyCode == Keyboard.W){
playSound(note2);
btn2.gotoAndStop(2);
}
}
stage.addEventListener(KeyboardEvent.KEY_UP, myKeyUp2);
function myKeyUp2(e:KeyboardEvent):void{
if (e.keyCode == Keyboard.W){
btn2.gotoAndStop(1);
}
}
however I cannot seem to get this method to work using external sound clips. here is my code so far:
var note1:Sound = new Sound();
note1.load(new URLRequest(“un.mp3”));
btn1.addEventListener(MouseEvent.CLICK,playSound);
function playSound(e:MouseEvent):void{
note1.play();
}
//hovers
btn1.addEventListener(MouseEvent.MOUSE_UP, bOut1);
btn1.addEventListener(MouseEvent.MOUSE_DOWN, bDown1);
function bDown1(event:MouseEvent):void {
btn1.gotoAndStop(2);
}
function bOut1(event:MouseEvent):void {
btn1.gotoAndStop(1);
}
btn1.buttonMode = true
//keyboard
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void{
if (e.keyCode == Keyboard.Q){
playSound(note1);
btn1.gotoAndStop(2);
}
}
stage.addEventListener(KeyboardEvent.KEY_UP, myKeyUp);
function myKeyUp(e:KeyboardEvent):void{
if (e.keyCode == Keyboard.Q){
btn1.gotoAndStop(1);
}
}
I have searched all over the forums and the internet and cannot seem to find an answer for my issue, any help that one could offer would be greatly appriciated!