Jump to content
Search Community

Same 1 LoaderItem in multiple Queues, question about dispose

Urda test
Moderator Tag

Recommended Posts

UPDATE, see post 2

 

Hello again,

 

[ Praise LoaderMax here :) ]

 

I have a question concerning Loadermax.dispose(false).

 

Same LoaderItem in 2 queues.

When i call queue1.dispose it doesnt matter if i pass true or false.

The LoaderItem/content is deleted anyway.

Why is this ?

 

Code:

// just some normal XML, nothing nested in XML, no LoaderMax-nodes inside. 

var loader1:XMLLoader = new XMLLoader("assets/xml/appConfig.xml",  { name:"loader1" } );

var queue1:LoaderMax = new LoaderMax( { name:"queue1", onComplete:handleQueue1} );
var queue2:LoaderMax = new LoaderMax( { name:"queue2", onComplete:handleQueue2} );	

queue1.append(loader1); // same Loader
queue2.append(loader1); // same Loader

queue1.load();
queue2.load();

private function handleQueue2(e:LoaderEvent):void 
{
     trace("There IS content before: " + LoaderMax(LoaderMax.getLoader("queue2")).content );

     trace("calling queue1.dispose(false) now");
     LoaderMax(LoaderMax.getLoader("queue1")).dispose(false);

     //null
     trace("NO content in Q2 after q1.dispose: " + LoaderMax(LoaderMax.getLoader("queue2")).content );
     //error, loader1 rip 
     trace("Same as: " + XMLLoader(LoaderMax.getLoader("loader1")).content );
}

 

In other words: How do i destroy a queue, but still keep the children if they are referenced by another queue ?

Im thinking about using LoaderMax as a kind of "RemoteResource-Manager" because it already offers so much of the functionality i need.

The same Resource might be used in different Modules/Classes each having its own queue with exclusive and commonly used Resources. When i destroy a module, i also want its queue destroyed (but not the LoaderItems/Content).

 

Is this possible ?

Link to comment
Share on other sites

I dont know -exactly- why, but calling an additional empty(false,false) before dispose seems to do the trick.

Again, dispose true or false doesnt matter.

 

... in handleQueue2...

 

LoaderMax(LoaderMax.getLoader("queue1")).empty(false, false);
LoaderMax(LoaderMax.getLoader("queue1")).dispose(false); // or true?

 

I checked FlashDevelops debug-stack and everything is as it should be:

queue1 is dead, queue2 alive, only one loader1 left.

 

Still alittle confused why it doesnt matter if i pass true or false...

Anyway thanks a lot for LoaderMax.

Link to comment
Share on other sites

Yep, this is all expected behavior. Let me explain...

 

When you dispose(false) a LoaderMax instance, it disposes all of its children too (kinda makes sense, otherwise all the children would hang around in memory and you'd have to manually loop through them all and dispose() each one). When a loader is disposed, it removes itself from all LoaderMax instances to which it belongs.

 

So in your example, if you dispose(false) queue1, that common child loader is disposed too which means now queue2 is empty. Therefore, when you get the content of queue2, the array will be empty because there are no loaders left in queue2 (remember, a LoaderMax's "content" is just an array of all of its child loaders' content). No loaders, no content.

 

And of course after a loader/queue is disposed, you won't be able to find it with getLoader() or getContent() because it doesn't exist anymore.

 

Your inclination to use empty() first on queue1 before you disposed it was good because doing so protected that child loader from being disposed. empty() just removes the children from that particular LoaderMax queue.

 

And of course you can use loaders in a standalone fashion too - you don't need to put them into a LoaderMax queue in order for them to work. LoaderMax instances are just a great tool for organizing things, loading a sequence, and reporting their progress as a whole.

 

Does that clear things up for you now?

Link to comment
Share on other sites

Yes, thank you.

Now everything makes perfect sense.

And of course you can use loaders in a standalone fashion too

I know, saves some performance i guess.

But since i dont know how many children a particular module will have in advance (runtime, most have more than one loader anyway), i always use a queue for uniformity/better Interface.

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