My favorites | Sign in
Project Logo
                
Search
for
Updated Nov 10, 2007 by debert
Labels: Phase-Implementation
AcessingLoadedContents  
How to fetch assets from BulkLoader

Once you have created a BulkLoader instance and added items to it, you can fetch those items by a number of ways.

Getting content from a loading item

The simplest way to get content is using the getContent method. If you have an item added such as:

bulkInstance.add("background.jpg", {id:"bg"});

You can later retrieve it with:

bulkInstance.getContent("background.jpg")

Or you can also use the item id, if you specified one:

bulkInstance.getContent("bg")

getContent will return an untyped object. If the loading has not completed or failed for some reason it will return null. BulkLoader will trace an error message.

After using getContent you can cast and use you asset:

var content : * = bulkInstance.getContent("background.jpg");
var bgBitmap : Bitmap = content as Bitmap;
addChild(bgBitmap);

Fetching content functions (see below) all use the same signature: get(key : , clearsMemory : Boolean = false); key -> Can be an url as a string, an id as a String or a URLRequest object that was specified when adding the item clearsMemory -> A boolean that defaults to false. If true, BulkLoader will remove all references to that asset and subsequent calls to use that item or it's content will fails. This is useful for memory management.

Using the convenience functions for automatic casting

You can ask BulkLoader to return some asset in the expected format. This is just a convenience so that casting is not required.

If you have an item added such as:

bulkInstance.add("background.jpg", {id:"bg"});

You can later retrieve it with:

bulkInstance.getBitmap("background.jpg"); // returns a flash.display.Bitmap object
bulkInstance.getBitmapData("background.jpg"); // returns a flash.display.BitmapData object

If the casting fails BulkLoader will trace a debug error message and will return null;

These are the available convenience methods:


Comment by ProllyROB, Dec 18, 2007

Im am trying to access loaded FLV's and play them threw the FLVplayback component.. what am i doing wrong?

import br.com.stimuli.loading.BulkLoader?;

var loader : BulkLoader? = new BulkLoader?("main-site");

loader.add("test.flv", {pausedAtStart:"true"}); loader.addEventListener(BulkLoader?.COMPLETE, onCompleteHandler); loader.start();

function onCompleteHandler(evt : ProgressEvent?):void {

trace("LOADED"); //Gave the FLVplayback compnent an instance name vid/// vid.play(loader.getContent("test.flv"));
}

Hosted by Google Code