import multiple sounds in a for each loop, actionscript 3
So im recreating my ear training program with more effective coding so i can add on to it. original i did.
//88 C8
var mp3Req88:URLRequest = new URLRequest("88.mp3");
var mp3_88:Sound = new Sound();
mp3_88.load(mp3Req88);
I basically got 88 sound files (each note of the piano) doing this code 88 times for each sound. with mathamatical equations made my ear training program.
Is there a simpler way to import these sounds in a loop of some sort so i dont have to do this 88x for the piano and however many times for the other instruments i will 开发者_高级运维be including?
thus var i have tried things along the lines of below with failure
var i:int;
for (i = 0; i < 5; i++)
{
var pianoMP3Req+i:URLRequest=new URLRequest("piano/"i+"mp3");
var pianoMP3_+i:Sound=new Sound();
pianoMP3_+i.load(pianoMP3Req+i);
}
I am not sure if your strings concatenate correctly (if they correctly produce the valid filename.)
Try like this:
var i:int;
for (i = 0; i < 5; i++) {
var request = pianoMP3 + "" + i;
request:URLRequest=new URLRequest("piano/" + i + ".mp3");
var temp = pianoMP3 + "" + i;
temp:Sound=new Sound();
temp.load(request);
}
for both the request and the mp3. I don't have an environment to test it at the monent.
精彩评论