# One Function, multiple buttons

**URL:** <https://forum.kirupa.com/t/one-function-multiple-buttons/275578>\
**Category:** flash\
**Created:** [November 16, 2008, 6:28am UTC](https://forum.kirupa.com/t/one-function-multiple-buttons/275578 "2008-11-16T06:28:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stinkmoe](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@stinkmoe](https://forum.kirupa.com/u/stinkmoe)\
**Post date:** [November 16, 2008, 6:28am UTC](https://forum.kirupa.com/t/one-function-multiple-buttons/275578/1 "2008-11-16T06:28:55Z")

</div>

I have three buttons. My goal is that each button will load and play a sound file from the internet. Here is what I have:

> 

function loadPlaySnd(pSpecifier1:String):void {

```
arguments;

SoundMixer.stopAll();

var sndRequest:URLRequest = new URLRequest ();
sndRequest = new URLRequest ("http://www.geocities.com/stinkmoe/"+pSpecifier1+".mp3");

var snd:Sound = new Sound ();
snd.load(sndRequest);
snd.addEventListener(Event.COMPLETE, loadingCompleteHandler);	

function loadingCompleteHandler(e:Event):void {
	trace ("Sound has loaded");
	snd.play();
}

```

}

basketball\_btn.addEventListener(MouseEvent.CLICK, function () {loadPlaySnd(“basketball”);});  
whistle\_btn.addEventListener(MouseEvent.CLICK, function () {loadPlaySnd(“whistle”);});  
scoreboard\_btn.addEventListener(MouseEvent.CLICK, function () {loadPlaySnd(“scoreboard”);});

My problem is this:  
Every Button I press goes to the same sound file. The best I can figure, is that the file I loaded the first time I pressed a button has been uploaded, and from there I cannot load another file over that variable when I try another button. Anything blatantly wrong with what I’m doing? Do I need to clairify anything here?

Do I need to clear my variables somehow when the sound finishes playing?
