Jump to content
Search Community

Loading Assets on Requst: Garbage Collection/Optimiation ?

Thomas James Thorstensson test
Moderator Tag

Recommended Posts

Hi

 

Im doing a 360 VR rotate tool which is based on a 2 dimensional array of images.

 

At the moment no queloading in place but first port of call is to load the requested image in view. There are lots of images. At the moment my AssetLoaderProxy class has

 

public function handleImageRequested(imgStr:String):void {

var queue:LoaderMax=new LoaderMax({onProgressHandler:handleProgress, onComplete: handleImageLoaded});

queue.append(new ImageLoader("assets/img/" + imgStr, {name: "photo1"}));

queue.load();

}

 

It seems to me this is perhaps not best practice as I am everytime method is called creating a new instance of LoaderMax. I havent checked the GC yet but suspect this will force things to run slower.

 

What would be best way of doing such a method as above. I need to use queue as background loading will be added to this.

 

 

Thanks on beforehand

 

Thomas

Link to comment
Share on other sites

if you want your loader to persist, create it outside your function:

 

 

var queue:LoaderMax=new LoaderMax({onProgressHandler:handleProgress, onComplete: handleImageLoaded});

 

public function handleImageRequested(imgStr:String):void {

 

queue.append(new ImageLoader("assets/img/" + imgStr, {name: "photo1"}));

queue.load();

}

 

once all of your images are loaded you can then dispose/unload it.

 

you may want to also find a way to give each loader a unique name instead of naming them all "photo1" so that any future calls to LoaderMax.getLoader or LoaderMax.getContent will be more intuitive and trouble-free.

ideally you would want to be able to do LoaderMax.getLoader("photo30")

Link to comment
Share on other sites

Yes done so

 

Doing the following now

 

LoaderMax.activate([imageLoader]);

mainQueue=LoaderMax.parse(dimVO.oneArr, {onProgress: handleAllProgress, onComplete: handleAllImagesLoaded}, {autoPlay: false});

mainQueue.prependURLs('assets/img/');

 

Where I parse an array of images.

 

Question:

 

Is there any way for me to get LoaderMax to name each image on the fly or does it somehow keep a named reference that I can acess. Cause I would like to be able to do the above

AND prioritize any requested image with

 

LoaderMax.prioritize("mylittlename");

 

 

Thanks

 

Thomas

Link to comment
Share on other sites

Is there any way for me to get LoaderMax to name each image on the fly or does it somehow keep a named reference that I can acess. Cause I would like to be able to do the above

AND prioritize any requested image with

 

LoaderMax.prioritize("mylittlename");

No, but remember that you can use a name OR a URL to find loaders. So in your example, you could do:

 

var myLoader:ImageLoader = LoaderMax.getLoader("assets/img/" + dimVO.oneArr[0]);

 

That'll get the first image in the array. Or you could loop through that array, use LoaderMax.getLoader() to get each individual loader, and set its "name" property to whatever you please. Maybe you've got another array that stores the names and you tap into the index value to associate them. Lots of options. You could also use the LoaderMax's getChildren() method to get an array of all the child loaders in the LoaderMax instance that results from your parse().

 

Hope that helps.

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...