Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-09-2005, 03:09 PM   #1
nawebb79
Registered User
 
Join Date: May 2005
Location: New York, NY
Posts: 33
Default Preloading multiple mp3's using looping arrays

I am preloading multiple mp3's dynamically using a looping array and it is working very well. However, I would like to display the percentage of the last mp3 loaded by the array. Does anyone know how I would modify the code to do this:

ActionScript Code:
var my_array:Array = new Array(); my_array[0] = "Audio/audio_1.mp3"; my_array[1] = "Audio/audio_2.mp3"; my_array[2] = "Audio/audio_3.mp3"; my_array[3] = "Audio/audio_4.mp3"; count = 0; var k; for (k in my_array) {     var my_audio:Sound = new Sound();     my_audio.loadSound(my_array[k], true);     my_audio.setVolume(0);     var my_interval2:Number;     my_interval2 = setInterval(checkAudioProgress, 100, my_audio);     function checkAudioProgress(the_audio:Sound):Void {         var AudioKBytes = Math.ceil(the_audio.getBytesTotal()/1024);         var AudioPct:Number = Math.round(the_audio.getBytesLoaded()/the_audio.getBytesTotal()*100);         AudioPctOutput = "Loading Audio: "+AudioPct+"%"+" of "+AudioKBytes+" k";     }     count++; }

I'm working against a deadline so any extra help would be greatly appreciated.

Many Thanks.
nawebb79 is offline   Reply With Quote
Old 06-10-2005, 03:11 AM   #2
madgett
is my last name...
 
Join Date: May 2004
Posts: 964
Default

For..in loops work backwards with arrays. So 3 is first then 2 then 1 then 0. So just loop using defined numbers. You don't want the function in the for loop because it only needs to be used once. You're code will look something like this:
ActionScript Code:
var my_array:Array = new Array(); my_array[0] = "Audio/audio_1.mp3"; my_array[1] = "Audio/audio_2.mp3"; my_array[2] = "Audio/audio_3.mp3"; my_array[3] = "Audio/audio_4.mp3"; count = 0; var k; for (k=0; k<my_array.length; ++k) {     trace(k);     var my_audio:Sound = new Sound();     my_audio.loadSound(my_array[k], true);     my_audio.setVolume(0);     var my_interval2:Number;     my_interval2 = setInterval(checkAudioProgress, 100, my_audio);     if (k == my_array.length-1) {         checkAudioProgress(my_array[k]);     }     count++; } function checkAudioProgress(the_audio:Sound):Void {     var AudioKBytes = Math.ceil(the_audio.getBytesTotal()/1024);     var AudioPct:Number = Math.round(the_audio.getBytesLoaded()/the_audio.getBytesTotal()*100);     AudioPctOutput = "Loading Audio: "+AudioPct+"%"+" of "+AudioKBytes+" k"; }
madgett is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:49 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.