Error #1009 - the most stupid AS3 loader issue ever !!!
Ziggizag Oct 8, 2009 5:20 PMHi,
(It's about AS3 / Flash CS4)
As a developer I often have no controll what is the content of a movie being runtime-loaded. I must presume I have no control on it at all - movie clips are marketed and sold and the only thing expected is that they play nice. And they are supposed to be runtime-loaded by a simple "progress-bar" style loader.
The loader movie itself is fine. Though it's not sort of these tricky "no timeline, document-class only" it used to do the job.
The main code is as folllows:
FRAME 2:
var thisRequest:URLRequest = new URLRequest("movie.swf");
var thisLoader:Loader = new Loader();
var newContent:MovieClip;
thisLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, doneLoading);
function doneLoading(evt:Event):void{
newContent = MovieClip(thisLoader.content);
//stage.addChild(newContent); -- please notice I commented this line !!!
}
FRAME 3:
thisLoader.load(thisRequest);
As you may see, it's nothing special - just regular loader stuff here...
But the issue is that it throws errors just in case of some loaded SWFs.
Another words - the content and structure of movie.swf impact the loader performance!
Too often I notice this kind of error being thrown right after "thisLoader.load(thisRequest);" is execuded:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at movie_fla::MainTimeline/frame8()
Right after - that means BEFORE adding loaded movie to the Stage childlist etc.
I said - right after movie.swf is invoked by the "load" command !
This is really rediculous!
I do not expect this sort of behavior! I expect the loaded movie to be quiet unless explicitly added to stage with:
stage.addChild(newContent);
But in a contrary - it seems the loaded movie becomes somewhat active right after being loaded - even before being added to stage. And in some cases this prematured activity leads to hard-to-controll errors! Please notice the error is thrown despite line where loaded content is added to stage is commented!
I said what I wanted to say - now dear Flash AS3 experts and mastahakas please - give me some advice what to do in this situation.
I am really, really confused as I want to write clean, error-free code and I get run out of ideas how to deal with this nasty issue.
Rgs,
Ziggi

