Reloading SWF a second time gets an error
I'm having an odd issue with reloading SWFS. I start of with loading my SWF:
var req:URLRequest = new URLRequest( "RegionalIntro.swf" );
req.method = URLRequestMethod.POST;
req.data = true; // POST requests require non-null data
introSWF = new Loader();
introSWF.load(req);
addChild(introSWF);
Then once I'm finished I unload:
removeChild(introSWF);
introSWF.unloadAndStop(true);
Now when I want to reload the SWF I run the first bit of code again I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I cant work out why I'd get that the second time it loads and not the first. It's supposed to just be the same? This is being done inside Windows Projector .exe file, it's going to run as a kiosk application.
EDIT:
at com.company.THPassport.exRegional::exRegionalIntro/skipTablet()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.company.THPassport.exRegional::exRegionalLoader/userLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.company.THPassport.utilities.DB::user/loadUserData()
at com.company.THPassport.utilities.DB::user/checkExistingUserLoadedXML()
at flash开发者_Python百科.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
As far as I can see it's getting an error from here:
currentUser = e.data;
maxspeechB.parent.removeChild(maxspeechB);
maxspeechA.parent.removeChild(maxspeechA);
wallstageA.parent.removeChild(wallstageA);
tabletfalls.parent.removeChild(tabletfalls);
tabletvanishes.parent.removeChild(tabletvanishes);
wallfills.alpha = 0;
if (currentUser.getCompleteAreas() == 1) {
wallfills.gotoAndStop(40);
} else if (currentUser.getCompleteAreas() == 2) {
wallfills.gotoAndStop(80);
} else if (currentUser.getCompleteAreas() == 3) {
wallfills.gotoAndStop(120);
}
wallstageB.alpha = 1;
Tweener.addTween(wallfills,{ alpha:1, time:1, transition: "linear", onComplete:dropSignpost});
What I can't work out is why that works the first time, but when it's reloaded it doesn't work?
EDIT2: The plot thickens, I can catch the error by surrounding all of the code in the function at the top of the stack trace with a try/catch block. I trace the error and its the same, the weird thing is all the code executes as expected. All works fine and throws an error ... very odd! I'd hate to leave it like this without finding out why it's doing it though ...
Try to add a complete event listener to the loader.contentLoaderInfo
and do everything below loader.load
(like addChild(introSWF);
)in the event listener handler. Even if not required, it helps you prevent the situation in which you are trying to use an object that hasn't load yet.
Ben - is there a second line to that error? It might tell you that the error is thrown by the "RegionalIntro.swf", not your wrapper swf.
It's possible that something's going on in that SWF that's timing related. In other words - it might utilize some asset that needs to be loaded/initialized before it's called, and sometimes, it isn't ready yet.
精彩评论