# Document class vs import

**URL:** <https://forum.kirupa.com/t/document-class-vs-import/308530>\
**Category:** Uncategorized\
**Created:** [April 25, 2010, 1:23am UTC](https://forum.kirupa.com/t/document-class-vs-import/308530 "2010-04-25T01:23:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobthebob](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@bobthebob](https://forum.kirupa.com/u/bobthebob)\
**Post date:** [April 25, 2010, 1:23am UTC](https://forum.kirupa.com/t/document-class-vs-import/308530/1 "2010-04-25T01:23:07Z")

</div>

I’m just wondering about the difference between using an external .as file as a Document Class vs importing it via some timeline code like:

```auto
import Pixoid;
var pixMC:Sprite = new Pixoid();
pixMC.x = 0
pixMC.y = 0
addChild(pixMC);

```

one thing I have noticed is that altho the above timeline code works certain objects return the “null object” error.  
for example if in my Pixoid.as file I have any references to the ‘stage’ object  
ex:

```auto
pxRow = stage.stageWidth / 10; 

```

it returns

```auto
"Error #1009 Cannot access a property or method of a null object reference."

```

so, is there any advantage to using the import strategy vs the Document Class one? should I not worry about it and continue on my happy way with the Document Class?  
I’m asking because I first ran into this problem with Flex and had to do some kludges to get around it - defining UIContainer object etc - but now that I have found it to also exist in Flash, I’d love an explanation as to why it works like this. when I posted about this problem in the Flex forums kindly gurus gave me the workaround but I never really understood the explanations as to _why_ it worked.  
thanks in advance.  
bvb
