|  | attaching Sounds by looping |  | |
| | | bhnh |  |
| Posted: Thu Jul 31, 2008 7:34 pm Post subject: attaching Sounds by looping |  |
I've got ten .mp3 files in my library(all with linkage) named "cbleep_"+(0 to 9). I'd like to create ten Sound objects and attach the .mp3s to them. I've done it - laboriously - one by one, but it seems to me it should be able to be done with a simple loop. Been wrestling with all afternoon, with no luck. Below is where I'm at. Any guidance would be enormously appreciated. Thanks!
//array of mp3 file names in library var bleeps:Array = new Array(); var audio:Array = new Array(); //for 10 sounds for(var i:Number=0;i<10;i++){ //push the names of the mp3 clips bleeps.push("\""+"cbleep_"+i+"\""); //create 10 entries in the audio array audio.push(i); //make each audio entry a new Sound object audio[i] = new Sound(); //attach the sounds from the library audio[i].attachSound(bleeps[i]);
}
btn.onPress = function(){ audio[5].start(); //nothing happens } |
| |
| | | kglad |  |
| Posted: Thu Jul 31, 2008 9:07 pm Post subject: Re: attaching Sounds by looping |  |
try:
for(var i:Number=0;i<10;i++){ //make each audio entry a new Sound object audio[i] = new Sound(); //attach the sounds from the library audio[i].attachSound("cbleep_"+i);
} |
| |
| | | bhnh |  |
| Posted: Thu Jul 31, 2008 9:41 pm Post subject: Re: attaching Sounds by looping |  |
Kglad to the rescue yet again. Jeez, I'm gonna have to put you on retainer.
The only addition to your code (which you probably intended) to make it work was to make audio an array first. Works like a charm. Many thanks!
audio = new Array();
for(var i:Number=0;i<10;i++){ audio.push(i); audio[i] = new Sound(); audio[i].attachSound("cbleep_"+i); }
btn.onPress = function(){ audio[8].start(); //victory! } |
| |
| | | kglad |  |
| Posted: Thu Jul 31, 2008 10:06 pm Post subject: Re: attaching Sounds by looping |  |
| you're welcome. (i was just re-coding your for-loop.) |
| |
|
|