Jump to content
Search Community

ImageLoader - Reusing

ukla test
Moderator Tag

Recommended Posts

I have an instance of the ImageLoader.

 

_loader = new ImageLoader("image.jpg", {name:"image1", x: stage.stageWidth * 0.5, y: stage.stageHeight * 0.5, width: 800, height: 600, container:this, scaleMode:"proportionalOutside", centerRegistration:true, onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

_loader.load();

 

Later I want to load an image into that same ImageLoader (_loader).

 

_loader.unload();
_loader = new ImageLoader("image2.jpg", {name:"image2", container:this, scaleMode:"proportionalOutside", centerRegistration:false});
_loader.load();

 

Is that the best way to do it? I am wondering b/c I am creating another "new ImageLoader" ... figured it would be easier to write _loader.load(urlOrRequest:*, vars:Object = null).

Link to comment
Share on other sites

What's your objective - why are you trying to reuse the same ImageLoader? It looks like you're using a different url, different options for the image (one centers the registration, the other doesn't), etc. - it sure seems like it would be appropriate to just create a new one. If all you're doing is changing the url, you could then flush it and reload with load(true), but its ContentDisplay will get refreshed to the new content so you'll lose the old stuff. I suspect it'd be cleaner to just create a new ImageLoader. I think that sometimes people go way overboard in trying to reuse instances in order to improve performance by minimizing new object creation, but they don't realize all the costs involved in cleaning the original object for reuse and it often actually ends up degrading performance a bit when you consider all the factors.

Link to comment
Share on other sites

Jack,

 

My apologies for the poor example. Here is a full screen image site I did a few months ago - http://www.brennanwesley.com/.

 

In that example, I created a full screen image class. Basically it is a single loader that loads content over and over and over. All of the images are the same size.

 

So my objective in this case is to use your Loader package for future projects ... just trying to understand best practices.

 

Thanks,

Craig

 

PS. I tend to over complicate things. Working on fixing that.

Link to comment
Share on other sites

No problem. Yeah, since you're fading the content into place (so both images are showing at the same time while they transition), you should definitely create a new ImageLoader each time. You can dispose() the old one when you're done, though. Make sure you set the "flush" parameter to "true" in dispose() (like loader.dispose(true)) to force the content to unload too. Otherwise it will just dispose of the loader itself, not the content.

 

Does that answer your question?

Link to comment
Share on other sites

Yes, that makes sense.

 

In my example I am doing it differently. I have a bitmap that resides below the loader (image). Each time a new image is loaded, I draw the current image data to the bitmap. So it appears as though images are loading on top of images.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...