By loaded, do you mean entirely loaded, or with no load call? If a load call is acceptable, the following could be useful. The progress event gives the incoming data's Total size on the first fire. We merely let a given progress event fire, take the total value of the current loading item and add that to our own _total variable; We continue this until our dataprovider (array, xml, etc) is empty. by the end you have the sum of all your assets totals.
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.URLLoader;
import flash.URLRequest;
public class ExampleDocumentClass extends Sprite
{
private var _urlLoader:URLLoader;
private var _loader:Loader;
private var _request:URLRequest;
private var _total:Number;
private var _array:Array;
public function ExampleDocumentClass():void
{
if(stage) _init;
else addEventListener(Event.ADDED_TO_STAGE, _init);
}
private function _init(e:Event = null):void
{
_array = [{type:"nonDisplay", path:"path/to/file"},{type:"display", path:"path/to/file"}];
_urlRequest = new URLRequest();
//Non display asset
_urlLoader = new URLLoader();
_urlLoader.addEventListener(ProgressEvent.PROGRESS, _onProgress);
//Display asset
_loader = new Loader();
loadAsset();
}
private function loadAsset():void
{
if(_array.length > 0)
{
var pObj:Object = _array[0];
if(pObj.type == "nonDisplay")
{
loadNonDisplayAsset(pObj.path);
}
else
{
loadDisplayAsset(pObj.path);
}
//Remove this item from the array;
_array.shift();
}
}
private function loadNonDisplayAsset(pAsset:String):void
{
_urlRequest.url = pAsset;
_urlLoader.load(_urlRequest);
}
private function loadDisplayAsset(pAsset:String):void
{
_urlRequest.url = pAsset;
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, _onProgress);
_loader.load(_urlRequest);
}
private function _onProgress(e:ProgressEvent):void
{
_total += e.bytesTotal;
_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, _onProgress);
_urlLoader.removeEventListener(ProgressEvent.PROGRESS, _onProgress);
}
}
}
So we load an asset just long enough to append its Size total, to our own _total variable and then we call the next item in the array and append its total until the data provider is empty. Obviously this could be done with XML, or however you wish, an array is just what i used for the exercise.
Brian Hodge
hodgedev.com
blog.hodgedev.com