Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / July 2008



Tip: Looking for answers? Try searching our database.

attaching Sounds by looping

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bhnh - 31 Jul 2008 20:34 GMT
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.)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.