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 - 31 Jul 2008 22:07 GMT
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 - 31 Jul 2008 22:41 GMT
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 [b]audio[/b] 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 - 31 Jul 2008 23:06 GMT
you're welcome. (i was just re-coding your for-loop.)