I'm getting "TypeError: Error #1009: Cannot access a property or method of a null object reference." when I load a swf, but it works fine on it's own.
Remember way long ago when you wrote it AS2 how whenever you were writing a swf that would be pulled into another swf you were really careful with _root, because it changed places?
AS3 has two things like that, root (same as _root) and stage. Using either without properly thinking through the consequences can be bad. The references to stage are what I seem to be running into the most.
Why? stage is only a valid reference once the loaded swf is added to the display list, via addChild. Until then it is null. A loading swf starts executing code when the first frame is ready, and it doesn’t always make sense in many template cases to add a swf until it is fully loaded, since you don’t know it’s content.
Therefore it is good practice to not reference stage in the code of any swf that is designed for the purposes of being a part of a website rather than a full website, such as a contact page or an image viewer. Because it creates many possible problems for someone when they try to implement it.
If you need stage in your components, try running an if statement if (stage) before using it, or only using stage on the Event.ADDED_TO_STAGE event so that you know it’s in the display list, and remember the Event.REMOVE_FROM_STAGE should then undo whatver things the Event.ADDED_TO_STAGE did, since stage will be null again.