# Loading random sound loops

**URL:** <https://forum.kirupa.com/t/loading-random-sound-loops/6885>\
**Category:** flash\
**Created:** [October 18, 2002, 7:04pm UTC](https://forum.kirupa.com/t/loading-random-sound-loops/6885 "2002-10-18T19:04:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shpek](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@shpek](https://forum.kirupa.com/u/shpek)\
**Post date:** [October 18, 2002, 7:04pm UTC](https://forum.kirupa.com/t/loading-random-sound-loops/6885/1 "2002-10-18T19:04:48Z")

</div>

Objective:  
Everytime a user enters this site, I’d like to have a different sound loop load.  
This is the code I am using to load the single sound clip.

mySound = new Sound();  
mySound.attachSound(“wav”);

This sound is also controled by a volume slider once it has loaded. Here is the code:  
onClipEvent (load) {  
top = \_y;  
left = \_x-48;  
right = \_x;  
bottom = \_y;  
\_x = \_root.volume\_level;  
}  
onClipEvent (enterFrame) {  
if (dragging) {  
\_root.mySound.setVolume(100+((\_x-right)\*2.1));  
}  
}

* * *

So can anyone tell me how to load a random sound clip (1of3) and then allow the slider control to “control” that partcular clip?

THANKS a TON!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 7:49pm UTC](https://forum.kirupa.com/t/loading-random-sound-loops/6885/2 "2002-10-18T19:49:57Z")

</div>

make an array with values 0-2 (that will be 3 choices) … each value will correspond to one of your song titles and when it’s selected it will play the song … then just put a random number picker math.random(2); before it

that should pick a number then play that number from the array … onLoad

i think that’ll work

pom?  
inigo?  
shuga? … oh wait … thats me 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 8:19pm UTC](https://forum.kirupa.com/t/loading-random-sound-loops/6885/3 "2002-10-18T20:19:16Z")

</div>

Hi and thanks for replying. I think I am understanding you but would you have any code that you could copy and paste in? I want to be sure I set the code up correctly. Would be a HUGE help.

Again, thanks!!!  
G

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 9:19pm UTC](https://forum.kirupa.com/t/loading-random-sound-loops/6885/4 "2002-10-18T21:19:33Z")

</div>

i don’t know how to make an array yet … i just know what they do but lemme see if i can find a sample that i think might work

i’ll post it in a few mins

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 18, 2002, 9:46pm UTC](https://forum.kirupa.com/t/loading-random-sound-loops/6885/5 "2002-10-18T21:46:16Z")

</div>

```auto

i=_root.math.random(2);
var myArray=new Array("mySong1.mp3","mySong2.mp3","mySong3.mp3");
mySound=newSound();
mySound.loadSound(myArray*,true);
mySound.start;

```

apparently pom and inigo … or any of the other gurus aren’t around today.

this is what i came up with and it’s not working for me yet … but i have to leave work now … so i’ll have to mess with it more later. sorry i’m not the most knowledgable person at actionscripting … i’m learning too 🙂

anyway … you should look around for tutorials and information on Arrays on the web or even on [Kirupa.com](http://Kirupa.com) … there are lots of resources out there … if i get it to work … i will certainly post it here

hope this helps … atleast a little bit

if any guru looks at my code … i’m getting an error when i trace the value of i … i get “undefined” in the error window. so i’m not sure how to fix that … i thought i supplied what i was supposed to be and where it was to be applied … but i dunno 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 21, 2002, 2:08pm UTC](https://forum.kirupa.com/t/loading-random-sound-loops/6885/6 "2002-10-21T14:08:46Z")

</div>

thanks alot for the effort. i’ll keep working it and if i figure it out i’ll post it here.
