Jump to content
Search Community

Unload or Dispose - When?

pol test
Moderator Tag

Recommended Posts

I tried unloading LoaderMax using an onComplete and I am getting a bunch of null object reference errors, runtime.

 

Here is my code:

var que:LoaderMax = new LoaderMax({name:"illusionsQue",onComplete:queComplete,onError:queError});
que.append(new SWFLoader("swf/illusions-print.swf",{name:"swfIllusionsPrint",estimatedBytes:725722,onProgress:illusionsProgress,onComplete:illusionsComplete}));
que.append(new SWFLoader("swf/illusions-digital.swf",{name:"swfIllusionsDigital",estimatedBytes:725722,onProgress:illusionsProgress,onComplete:illusionsComplete}));
que.append(new SWFLoader("swf/illusions-contact.swf",{name:"swfIllusionsContact",estimatedBytes:725722,onProgress:illusionsProgress,onComplete:illusionsComplete}));
LoaderMax.prioritize("swfIllusionsPrint",false);
que.load();

function illusionsProgress(e:LoaderEvent):void 
{ 
	var pg:String = e.target.name.replace("swfIllusions","");
	var progressTxt:String = String(new uint(Math.round(e.target.progress*100)) + "%");
	trace(pg," Loading: ",progressTxt);
	mcBg.mcMenu.pageProgress[pg].text = progressTxt;
}

function illusionsComplete(e:LoaderEvent):void
{
	var pg:String = e.target.name.replace("swfIllusions","");
	mcIllusions[pg] = LoaderMax.getContent(e.target.name).rawContent as MovieClip;
	mcIllusions[pg].x = 490;
	mcIllusions[pg].y = 100;
	illusionsReady[pg] = true;
	mcBg.mcMenu.updatePageStatus(pg);
	trace(e.target.name + " is complete!");
}

function queComplete(e:LoaderEvent):void
{
	que.unload();
	trace("unloading que");
}

function queError(e:LoaderEvent):void
{
	trace("error occured with " + e.target + ": " + e.text);
}
}

Link to comment
Share on other sites

Could you be more specific about the error(s)? What exactly is it saying? Can you upload a simple example that demonstrates the issue?

 

It looks like maybe you've got something funky happening with your mcIllusions and illusionsReady hash or whatever your "pg" variable is getting set to, like it's not finding what you think it's supposed to find. I'm pretty sure this has nothing to do with LoaderMax.

Link to comment
Share on other sites

Thanks. Actually the only line that is giving me the issue is:

que.unload();

 

Everything else works like a charm (all the loading).

 

Interestingly, when I replace que.unload with que.dispose, it also works perfectly.

 

I'll copy the errors and the latest code again below for the unload scenario if that helps?

 

What I notice on the unload is that it seems to start loading again immediately and that's when the error happens? Not sure why? (see below)..

 

Thank you!

 

Print  Loading:  9%
Print  Loading:  18%
Print  Loading:  27%
Print  Loading:  36%
Print  Loading:  45%
Print  Loading:  54%
Print  Loading:  63%
Print  Loading:  72%
Print  Loading:  81%
Print  Loading:  90%
Print  Loading:  99%
Print  Loading:  99%
Digital  Loading:  9%
Digital  Loading:  18%
Digital  Loading:  27%
Digital  Loading:  36%
Digital  Loading:  45%
Digital  Loading:  54%
Digital  Loading:  63%
Digital  Loading:  72%
Digital  Loading:  80%
Digital  Loading:  100%
swfIllusionsDigital is complete!
Print  Loading:  100%
swfIllusionsPrint is complete!
Contact  Loading:  9%
Contact  Loading:  18%
Contact  Loading:  27%
Contact  Loading:  36%
Contact  Loading:  45%
Contact  Loading:  54%
Contact  Loading:  63%
Contact  Loading:  72%
Contact  Loading:  81%
Contact  Loading:  84%
Contact  Loading:  100%
swfIllusionsContact is complete!
unloading que
Contact  Loading:  0%
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1309()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_dump()
at com.greensock.loading.core::LoaderItem/_dump()
at com.greensock.loading.core::DisplayObjectLoader/_dump()
at com.greensock.loading::SWFLoader/_dump()
at com.greensock.loading.core::LoaderCore/unload()
at com.greensock.loading::LoaderMax/_dump()
at com.greensock.loading.core::LoaderCore/unload()
at MethodInfo-1311()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()
at com.greensock.loading::LoaderMax/_loadNext()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()
at com.greensock.loading::SWFLoader/_completeHandler()
Digital  Loading:  0%
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1309()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_dump()
at com.greensock.loading.core::LoaderItem/_dump()
at com.greensock.loading.core::DisplayObjectLoader/_dump()
at com.greensock.loading::SWFLoader/_dump()
at com.greensock.loading.core::LoaderCore/unload()
at com.greensock.loading::LoaderMax/_dump()
at com.greensock.loading.core::LoaderCore/unload()
at MethodInfo-1311()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()
at com.greensock.loading::LoaderMax/_loadNext()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()
at com.greensock.loading::SWFLoader/_completeHandler()
Print  Loading:  0%
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1309()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_dump()
at com.greensock.loading.core::LoaderItem/_dump()
at com.greensock.loading.core::DisplayObjectLoader/_dump()
at com.greensock.loading::SWFLoader/_dump()
at com.greensock.loading.core::LoaderCore/unload()
at com.greensock.loading::LoaderMax/_dump()
at com.greensock.loading.core::LoaderCore/unload()
at MethodInfo-1311()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()
at com.greensock.loading::LoaderMax/_loadNext()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()
at com.greensock.loading::SWFLoader/_completeHandler()

 

And the code that is generating this:

function moduleLoader():void
{
var que:LoaderMax = new LoaderMax({name:"illusionsQue",onComplete:queComplete,onError:queError});
que.append(new SWFLoader("swf/illusions-print.swf",{name:"swfIllusionsPrint",estimatedBytes:725722,onProgress:illusionsProgress,onComplete:illusionsComplete}));
que.append(new SWFLoader("swf/illusions-digital.swf",{name:"swfIllusionsDigital",estimatedBytes:725722,onProgress:illusionsProgress,onComplete:illusionsComplete}));
que.append(new SWFLoader("swf/illusions-contact.swf",{name:"swfIllusionsContact",estimatedBytes:725722,onProgress:illusionsProgress,onComplete:illusionsComplete}));
LoaderMax.prioritize("swfIllusionsPrint",false);
que.load();

function illusionsProgress(e:LoaderEvent):void 
{ 
	var pg:String = e.target.name.replace("swfIllusions","");
	var progressTxt:String = String(new uint(Math.round(e.target.progress*100)) + "%");
	trace(pg," Loading: ",progressTxt);
	mcBg.mcMenu.pageProgress[pg].text = progressTxt;
}

function illusionsComplete(e:LoaderEvent):void
{
	var pg:String = e.target.name.replace("swfIllusions","");
	mcIllusions[pg] = LoaderMax.getContent(e.target.name).rawContent as MovieClip;
	mcIllusions[pg].x = 490;
	mcIllusions[pg].y = 100;
	illusionsReady[pg] = true;
	mcBg.mcMenu.updatePageStatus(pg);
	trace(e.target.name + " is complete!");
}

function queComplete(e:LoaderEvent):void
{
	trace("unloading que");
	que.unload();
}

function queError(e:LoaderEvent):void
{
	trace("error occured with " + e.target + ": " + e.text);
}
}

Link to comment
Share on other sites

I just spent more time trying to reproduce this by copying your exact code (and replacing some of the URLs to point at my sample swfs) and everything worked flawlessly. How can I reproduce this problem?

 

Are you using the latest version of LoaderMax?

 

It would be super fantastic if you could post a very simple FLA (and support files) that I can publish to see the error. I suspect there might be something off with your code elsewhere in your project, but it's tough to know without seeing things in context.

Link to comment
Share on other sites

Oh good, you found this code. It's good to hear that it worked perfectly for you with your mc's.

 

I'll be getting back to this portion of the project tonight and tomorrow and will take a second look. If I don't find the problem in my own code, I'll try to re-create it as you say in a simple FLA (which I already created the other day to begin testing that module). So I'll keep you informed of my progress. I'm pretty sure the issue is on my end as well... unless I created some very unusual context (even so, probably on my end). I originally asked because I didn't know if that's what unload was supposed to do and I just didn't understand the paradigm (or maybe I was using it incorrectly)?

 

Thanks so much. I truly appreciate your focus and assistance!

Pol

Link to comment
Share on other sites

Hi!

 

I was able to re-generate the same problem (after unload(), starts loading again(?) and breaks).

 

I've packaged up the simple test-FLA and related swfs for you to look at....?

 

NOTE: I've commented out the offending line // que.unload(); so you can see it working without. It also works fine with que.dispose(); but not unload()?

 

The problem is that my sample file (with 3 swfs) is greater than 1MB. Is there another way I can get it to you? And can I do so without posting it for everyone (as there are some proprietary SWFs in there)?

 

Thanks a bunch,

Pol

Link to comment
Share on other sites

Got the file(s) via e-mail. Thanks.

 

I’m confused – when you say “breaks”, I was expecting an error of some sort. Are you just thinking that it was broken because the unloaded loaders dispatch a progress event notifying that their progress has changed back to 0? If so, that’s normal. It doesn’t mean they’re actively loading again (check their status property and you’ll see) – it’s just notifying you that there was a change in their progress (back to 0). You don’t get that notification if you dispose() them for obvious reasons (a disposed loader should be non-existent, so it shouldn’t dispatch events anymore).

 

See what I mean? I published your swf and couldn’t get any errors or strange behavior, but maybe I’m missing something obvious.

 

Also, you’ve got stale versions of the GreenSock classes. I’d recommend updating. http://www.greensock.com/loadermax/

 

Does this help?

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