# Controlling external mp3 sound clips with keyboard commands

**URL:** <https://forum.kirupa.com/t/controlling-external-mp3-sound-clips-with-keyboard-commands/324587>\
**Category:** Uncategorized\
**Created:** [August 28, 2011, 10:49pm UTC](https://forum.kirupa.com/t/controlling-external-mp3-sound-clips-with-keyboard-commands/324587 "2011-08-28T22:49:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![r1chyb](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@r1chyb](https://forum.kirupa.com/u/r1chyb)\
**Post date:** [August 28, 2011, 10:49pm UTC](https://forum.kirupa.com/t/controlling-external-mp3-sound-clips-with-keyboard-commands/324587/1 "2011-08-28T22:49:25Z")

</div>

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! 🙂
