# Adding sound to a button array

**URL:** https://forum.kirupa.com/t/adding-sound-to-a-button-array/292372
**Category:** flash
**Created:** [July 13, 2009, 5:48pm UTC](https://forum.kirupa.com/t/adding-sound-to-a-button-array/292372 "2009-07-13T17:48:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Christina\_Kanpp](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@Christina\_Kanpp](https://forum.kirupa.com/u/Christina_Kanpp)
#### Post date: [July 13, 2009, 5:48pm UTC](https://forum.kirupa.com/t/adding-sound-to-a-button-array/292372/1 "2009-07-13T17:48:59Z")

</div>

Ok I have tried searching around for adding a beep to my buttons in AS3 I can’t seem to find anything that makes sense for my arrays. I need it to make the sound on click so I am pretty sure I need it to go under “doClick4”.

This is the sound code I was trying in the array:  
It just makes my whole site start over.

```auto
var soundReq: URLRequest = new URLRequest ("lock-beep.wav");
var sound: Sound = new Sound ();
var soundControl:SoundChannel = new SoundChannel();

sound.load(soundReq);

sound.addEventListener (Event.COMPLETE, onComplete);

function onComplete (event: Event): void
{
    soundControl = sound.play();
    

    }

```

This is my array for my buttons:

```auto
var buttonsArray4:Array = [btn_lock1, btn_lock2, btn_lock3, btn_lock4, btn_lock5, btn_lock6, btn_lock7, btn_lock8, btn_lock9, btn_lock0, btn_lock10, btn_lock11];

function setButtons4():void {
    for (var i:int=0; i<buttonsArray4.length; i++) {
        buttonsArray4*.id = i;
        buttonsArray4*.buttonMode = true;
        buttonsArray4*.mouseChildren = false;
        buttonsArray4*.mouseEnabled = true;
        buttonsArray4*.addEventListener(MouseEvent.ROLL_OVER,playOver4);
        buttonsArray4*.addEventListener(MouseEvent.ROLL_OUT,playOut4);
        buttonsArray4*.addEventListener(MouseEvent.CLICK,doClick4);
    }
}

function playOver4(event:MouseEvent):void {
    event.currentTarget.gotoAndPlay("over");
}

function playOut4(event:MouseEvent):void {
    event.currentTarget.gotoAndPlay("out");
}

function doClick4(event:MouseEvent):void{
    var currentBtn4:int = event.currentTarget.id;
    setSelectedBtn4(currentBtn4);
}
function setSelectedBtn4(id:int):void{
    for (var i:int=0; i< buttonsArray4.length; i++) {
        if (id == i) {
            buttonsArray4*.gotoAndPlay("down");
            buttonsArray4*.buttonMode = false;
            buttonsArray4*.mouseEnabled = false;
            buttonsArray4*.removeEventListener(MouseEvent.ROLL_OVER,playOver);
            buttonsArray4*.removeEventListener(MouseEvent.ROLL_OUT,playOut);
            buttonsArray4*.removeEventListener(MouseEvent.CLICK,doClick4);
} else {
            if(buttonsArray4*.currentLabel =="down"){
                buttonsArray4*.gotoAndPlay("out");
            }
            buttonsArray4*.buttonMode = true;
            buttonsArray4*.mouseEnabled = true;
            buttonsArray4*.addEventListener(MouseEvent.ROLL_OVER,playOver);
            buttonsArray4*.addEventListener(MouseEvent.ROLL_OUT,playOut);
            buttonsArray4*.addEventListener(MouseEvent.CLICK,doClick4);
        }
    }
}
setButtons4();

```
