Taking into consideration your data structure and not getting into the topic of it needs improvements, here is a blueprint of bulk loading based on your arrays.
Please note, this code assumes that the only objective is to preload all assets in the beginning and then use them from cache. If you want to make you application more efficient - you may want to store loaded assets elsewhere and access them as needed. But this is a different topic.
I tried to comment code as much as possible.
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.media.Sound;
import flash.net.URLRequest;
var array1:Array;
var array2:Array;
/**
* Number of arrays with convention array<int> in the scope
*/
var numArrays:int = 2;
/**
* Total umber of assets to load
*/
var numAssets:int = 0;
init();
function init():void
{
array1 = new Array();
array2 = new Array();
array1[0] = ["", "GuitarMicArray/Center.mp3", "GuitarMicArray/15.mp3", "GuitarMicArray/45.mp3", "GuitarMicArray/60.mp3", "GuitarMicArray/90.mp3"];
array1[1] = ["", "MicPics/SM57.jpg", "MicPics/SM57.jpg", "MicPics/SM57.jpg", "MicPics/SM57.jpg", "MicPics/SM57.jpg"];
array1[2] = ["", "MicPosPics/Center.jpg", "MicPosPics/15.jpg", "MicPosPics/45.jpg", "MicPosPics/60.jpg", "MicPosPics/90.jpg"];
array1[3] = ["", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg"];
array1[4] = ["", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg"];
array2[0] = ["", "GuitarMicArray/Center.mp3", "GuitarMicArray/15.mp3", "GuitarMicArray/45.mp3", "GuitarMicArray/60.mp3", "GuitarMicArray/90.mp3"];
array2[1] = ["", "MicPics/SM57.jpg", "MicPics/SM57.jpg", "MicPics/SM57.jpg", "MicPics/SM57.jpg", "MicPics/SM57.jpg"];
array2[2] = ["", "MicPosPics/Center.jpg", "MicPosPics/15.jpg", "MicPosPics/45.jpg", "MicPosPics/60.jpg", "MicPosPics/90.jpg"];
array2[3] = ["", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg", "GuitarPic/LesPaul.jpg"];
array2[4] = ["", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg", "AmpPics/Marshall.jpg"];
preloadAssets();
}
function preloadAssets():void
{
/**
* 1. Since mime types are mixed up in the same data provider - we should separate mime types into different more logical entites
* 3. Since array contain redundant assets - we shoul avoid loading assets more than once
* 2. We should define how many assets to be loaded
*/
var sounds:Array = [];
var images:Array = [];
for (var i:int = 1; i <= numArrays; i++)
{
// gain reference to array
var array:Array = this["array" + 1];
// loop through second dimensions
for each (var subArray:Array in array)
{
// loop through elements in the seond dimension
for each (var url:String in subArray)
{
/**
* We need additional validation
* 1. Make shure that current element is not an empty string
* 2. Identify mime type base on file extension
*/
// only if it is not an empty string - proceed
if (url != "")
{
// increment number of assets that must be loaded
numAssets++;
// populate either sounds or image array
// url.match(/(\w+)$/gi) extracts file extension
switch (url.match(/(\w+)$/gi)[0])
{
case "jpg":
// push image url into array of images urls
// if url is not present - push it
if (images.indexOf(url) == -1)
{
images.push(url);
}
break;
case "mp3":
// puch sound url into the array of aounds urls
// add only if url does not exist int ht e array
if (sounds.indexOf(url) == -1)
{
sounds.push(url);
}
break;
}
}
}
}
}
// at this point we are ready to load all assets
// invoke images loading
for each (url in images)
{
trace("image", url);
var loader:Loader = new Loader();
addListeners(loader.contentLoaderInfo);
loader.load(new URLRequest(url));
}
// invoke sounds loading
for each (url in sounds)
{
trace("sound", url);
var sound:Sound = new Sound();
addListeners(sound);
sound.load(new URLRequest(url));
}
}
function onError(e:IOErrorEvent):void
{
trace("error", e.target);
removeListeners(e.target as EventDispatcher);
}
/**
* Adds loading related listeners
* @param ed
*/
function addListeners(ed:EventDispatcher):void
{
ed.addEventListener(Event.COMPLETE, onLoadComplete);
ed.addEventListener(IOErrorEvent.IO_ERROR, onError);
}
/**
* Removes loading related listeners
* @param ed
*/
function removeListeners(ed:EventDispatcher):void
{
ed.removeEventListener(Event.COMPLETE, onLoadComplete);
ed.removeEventListener(IOErrorEvent.IO_ERROR, onError);
}
function onLoadComplete(e:Event):void
{
// remove listeners
removeListeners(e.target as EventDispatcher);
// decrement numAssets
numAssets--;
// when all assets are loaded - numAssets is zero
if (numAssets == 0)
{
// all assets are loaded and we can go ahead with the rest of application
}
}