Can i attach a document class at runtime?

i want to load a swf into a blank document, and force the SWF to a have a document class, and i don’t want to set the document class inside the file FLA, before composing it:sigh:

nope

…why?

What are you trying to do? You can replace a document class instance with a loaded clip:

var s:Stage = stage;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, function():void { 
	s.removeChild(root);
	s.addChild(loader.content);
});
loader.load(new URLRequest('external.swf'));

You won’t have access to the stage for a little while, but otherwise you have essentially replaced the document class… though there are some other small differences.

Edit: Although, I don’t think that there is really anything special about loading a movie into that position, so I’m tempted to agree with TheCanadian.

Isn’t the document class just a quick and easy way to import and instantiate a normal AS class? I don’t use it so may be wrong.

No, the document class is kinda like an extension of the Stage class. Basically it is a display class that is at the very base of everything. You should use it. It helps keep your code much cleaner.

Ah gotcha. I don’t use it because i use FlashDevelop rather than Flash. But i do see the benefit of using it now you’ve explained the point.

nikefido & Krilnon - my loaded swf needs to be code free, and i don’t want the designers to add a document class before composing the fla. :pa:
first i wanted to force the swf by adding one, but apparently this won’t work. i created the old document class instance from the main application and than loaded the code free swf from it, using the swf’s reference instead of using “this” :devious: