I see that the LoaderMax class provides a lot of ease when adding a loaded image to the stage. I have a situation where I have existing code where I have a URL, or bytes in an object that represent an image. If the bytes are there I load them (unfortunately in actionscript this is async even when bytes in memory). If the URL is used, I store the bytes so they are loaded quickly the next time (lazy load and cache).
I'm having a problem where using the data loader the image is not even loading. I have included the code below:
public function loadImageBytes(callback:Function, sessionId:String=null):DataLoader {
this.imageBytesCallback = callback;
if (_image == null && publicURL != null){
var loadName:String = "test"; //id+"-"+new Date().getTime(); //what i want this id to be so unique
var alternateURL:String = null;
publicURL = "http://www.greensock.com/wp-content/themes/greensock/images/greensock_member_on.png";
var loader:DataLoader = new DataLoader(publicURL, {name:loadName, format:"binary", estimatedBytes:25000,
autoDispose:true,
onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
loader.load();
attemptedLoad = true;
return loader;
}
return null;
}
function completeHandler(event:LoaderEvent):void {
trace("complete "+event.text);
_image = LoaderMax.getContent("test");
imageBytesCallback(this);
}
When this returns to _image the result is null (even though this image is obviously there if you go to the URL).
A few questions. I want to have the loader have a unique Id every time, however it seems that this was created to add the LoaderMax object to the stage instead of extracting out the raw bytes, and binding them to an Image object on the stage. Is that true, and is there any way to extract the bytes to the containing object? Would you recommend instead just having the LoaderMax object on the stage instead of an Image object?
It seems problematic that the completeHandler must know the content name of the LoaderMax. Doesn't this become an issue if you line up many images in a row to load as I'm planning on doing. The function only knows the Id if I include it within the scope of the function creating the LoaderMax. This means I can't pass the DataLoader back to the caller and allow it to wait on the complete event because it won't know what the content name is. Is there a way around this, or am I trying to use the class incorrectly.
Thanks for a great product. I have been using TweenLite and TransformManager and they have been great.