# Buttons and wav sound loops as3 (almost made it)

**URL:** <https://forum.kirupa.com/t/buttons-and-wav-sound-loops-as3-almost-made-it/317070>\
**Category:** Uncategorized\
**Created:** [December 9, 2010, 3:30pm UTC](https://forum.kirupa.com/t/buttons-and-wav-sound-loops-as3-almost-made-it/317070 "2010-12-09T15:30:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spellphonik](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@Spellphonik](https://forum.kirupa.com/u/Spellphonik)\
**Post date:** [December 9, 2010, 3:30pm UTC](https://forum.kirupa.com/t/buttons-and-wav-sound-loops-as3-almost-made-it/317070/1 "2010-12-09T15:30:09Z")

</div>

Hi,everyone

I’ve been trying to make a sound-loop player for quite some time now (i’m new to as3) and i’m pretty close to do it but still i need a little help.

Ok, i’ve made six letters converted them into buttons and i want them to play a different wav sound loop each one whenever i click on them and to stop the sound when i click again.

**This works fine for the first button but not for the rest of them because i dont know where to insert the similar code for the rest of the buttons.**

**Here’s the code that works perfect for the first button:**

import flash.media.Sound;

var sound:Sound = new The\_Rloop5();  
var soundControl: SoundChannel = new SoundChannel();

```
          button_s.addEventListener(MouseEvent.CLICK, playSound);
          button_sstop.addEventListener(MouseEvent.CLICK, stopSound);

```

function playSound(event:MouseEvent):void  
{  
soundControl = sound.play(0, int.MAX\_VALUE);  
button\_sstop.visible = true;  
button\_sstop.addEventListener(MouseEvent.CLICK, stopSound);  
button\_s.visible = false;  
button\_s.removeEventListener(MouseEvent.CLICK, playSound);

}

function stopSound(event:MouseEvent):void  
{  
soundControl.stop();  
button\_s.visible = true;  
button\_s.addEventListener(MouseEvent.CLICK, playSound);  
button\_sstop.visible = false;  
button\_sstop.removeEventListener(MouseEvent.CLICK, stopSound);

}

button\_sstop.visible = false;

**here’s the attempt to continue the code for the second button:**

import flash.media.Sound;  
var sound:Sound = new Afristic2();  
var soundControl: SoundChannel = new SoundChannel();  
button\_s.addEventListener(MouseEvent.CLICK, playSound);  
button\_sstop.addEventListener(MouseEvent.CLICK, stopSound);

function playSound(event:MouseEvent):void  
{  
soundControl = sound.play(0, int.MAX\_VALUE);  
button\_sstop.visible = true;  
button\_sstop.addEventListener(MouseEvent.CLICK, stopSound);  
button\_s.visible = false;  
button\_s.removeEventListener(MouseEvent.CLICK, playSound);

}  
function stopSound(event:MouseEvent):void  
{  
soundControl.stop();  
button\_s.visible = true;  
button\_s.addEventListener(MouseEvent.CLICK, playSound);  
button\_sstop.visible = false;  
button\_sstop.removeEventListener(MouseEvent.CLICK, stopSound);

}

button\_sstop.visible = false;

import flash.media.Sound;  
var sound2:Sound = new DSkiller4();  
var soundControl2: SoundChannel = new SoundChannel();  
button\_p.addEventListener(MouseEvent.CLICK, playSound2);  
button\_pstop.addEventListener(MouseEvent.CLICK, stopSound2);

function playSound2(event:MouseEvent):void  
{  
soundControl2 = sound.play(0, int.MAX\_VALUE);  
button\_pstop.visible = true;  
button\_pstop.addEventListener(MouseEvent.CLICK, stopSound2);  
button\_p.visible = false;  
button\_p.removeEventListener(MouseEvent.CLICK, playSound2);

}  
function stopSound2(event:MouseEvent):void  
{  
soundControl2.stop();  
button\_p.visible = true;  
button\_p.addEventListener(MouseEvent.CLICK, playSound2);  
button\_pstop.visible = false;  
button\_pstop.removeEventListener(MouseEvent.CLICK, stopSound2);

}

```
  button_pstop.visible = false;

```

Now the only thing that i managed to do is to play the same sound on both of the two buttons.  
Thank you for any help…
