0
votes

I know this has been asked before, but after trawling through every thread I could find for an hour I decided to just ask directly.

I have a SWF made in the Flash IDE constructed entirely in a document class (this is the first project in which I've used the document class, but there hasn't been any issues until now). Inside this there are many references to the stage for variables and such. I have another SWF (again all done in document class and the first external preloader I've tried to make) that preloads the main SWF. The problem I have is that - as the main SWF references the stage before it is added - I get a #1009 error.

I have already tried two methods of correcting this but, to my surprise, neither worked. The first was to add the SWF's loader before loading it, as this code shows:

package 
{
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.ProgressEvent;
    import flash.display.MovieClip;
    import flash.events.Event;

    public class claude_loader extends MovieClip
    {
        public var main_movie:Loader = new Loader  ;
        public function claude_loader()
        {
            addChild(main_movie);
            trace(main_movie.stage);
            main_movie.load(new URLRequest("claudia_summers.swf"));
            main_movie.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, load_progress);

        }
    public function load_progress(e:ProgressEvent):void
    {
        trace(e.bytesLoaded+ " out of: " + e.bytesTotal);
    }
}

But this changes nothing. I don't quite understand why, as the main_movie loader has a stage (as the trace confirms), so by my reasoning the loaded SWF should have no problems.

I also tried changing the main SWF to not run until an ADDED_TO_STAGE event is fired, but the event is being triggered before it's added (even when I play the main SWF by itself?).

Can someone please help me? Am I missing something really obvious?

P.S. I can post the main SWF code, but it's over 1000 lines long so not sure what part - if any - would be helpful.

1
What line exactly makes a problem? trace(main_movie.stage);? - Ivan Chernykh
your claude_loader instance is added to stage ? if not - this causes the problem - Ivan Chernykh
The problem comes from the loaded SWF, which references the stage. As it's being loaded externally it's running before it's added to the stage, which causes the error. - Laurence Summers
I didn't think claude_loader needed to be added, as it's a class? The loaded SWF is held by the main_movie Loader. - Laurence Summers
Of course , you need to add the claude_loader to stage too , it even extends MovieClip. when you adding it to stage , every child of it will be able to access stage too! - Ivan Chernykh

1 Answers

0
votes

Not sure how, but I've managed to get the ADDED_TO_STAGE listener working in the loaded swf, which has resolved the issue.