# Can i attach a document class at runtime?

**URL:** <https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105>\
**Category:** Uncategorized\
**Created:** [June 23, 2008, 7:46am UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105 "2008-06-23T07:46:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![maloola](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@maloola](https://forum.kirupa.com/u/maloola)\
**Post date:** [June 23, 2008, 7:46am UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/1 "2008-06-23T07:46:57Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [June 23, 2008, 4:52pm UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/2 "2008-06-23T16:52:48Z")

</div>

nope

---

<div class="post-metadata">

**Author:** ![nikefido](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@nikefido](https://forum.kirupa.com/u/nikefido)\
**Post date:** [June 23, 2008, 6:46pm UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/3 "2008-06-23T18:46:26Z")

</div>

…why?

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 24, 2008, 4:00am UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/4 "2008-06-24T04:00:46Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Iamthejuggler](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Iamthejuggler](https://forum.kirupa.com/u/Iamthejuggler)\
**Post date:** [June 24, 2008, 8:37am UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/5 "2008-06-24T08:37:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Fidodo](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@Fidodo](https://forum.kirupa.com/u/Fidodo)\
**Post date:** [June 24, 2008, 10:15am UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/6 "2008-06-24T10:15:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Iamthejuggler](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Iamthejuggler](https://forum.kirupa.com/u/Iamthejuggler)\
**Post date:** [June 24, 2008, 10:26am UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/7 "2008-06-24T10:26:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maloola](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@maloola](https://forum.kirupa.com/u/maloola)\
**Post date:** [June 26, 2008, 8:03am UTC](https://forum.kirupa.com/t/can-i-attach-a-document-class-at-runtime/264105/8 "2008-06-26T08:03:15Z")

</div>

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:
