# Adding objects to stage through as file

**URL:** https://forum.kirupa.com/t/adding-objects-to-stage-through-as-file/300334
**Category:** flash
**Created:** [November 19, 2009, 11:16am UTC](https://forum.kirupa.com/t/adding-objects-to-stage-through-as-file/300334 "2009-11-19T11:16:28Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![romit\_2034](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@romit\_2034](https://forum.kirupa.com/u/romit_2034)
#### Post date: [November 19, 2009, 11:16am UTC](https://forum.kirupa.com/t/adding-objects-to-stage-through-as-file/300334/1 "2009-11-19T11:16:28Z")

</div>

Hey this is my as code

```auto

package
{
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.text.TextField;
    
    public class thumbNail extends MovieClip
    {
        
        
        import flash.net.*;
        import flash.events.Event;
        public var loader:URLLoader;
        public var xml:XML;
        public var xmlList:XMLList;
        public var ontr:int;
        public var thumbText:TextField;
        public var thumbCont:MovieClip;
        private static var stageRef:Stage;

        
        public function thumbNail(ont:int):void
        {
            ontr = ont;
            loader = new URLLoader();
            loader.load((new URLRequest("xml/thumbNail"+ontr+".xml")));
            loader.addEventListener(Event.COMPLETE, xmlLoaded);
            stageRef = this.stage;
            
            
        }
        private function xmlLoaded(event:Event):void
        {
            var count:int = 0;
            
            xml = new XML(event.target.data);
            xmlList = new XMLList(xml.children());
            for(var i:int=0; i<xmlList.length(); i++)
            {
                thumbCont = new MovieClip();
                thumbText = new TextField();
                thumbText.text = xmlList*.attribute("title");
                //trace(thumbText.text);
                stageRef.addChild(thumbCont);
                thumbCont.addChild(thumbText);
                thumbText.textColor = 0x666666;
                thumbCont.x = -100;
                thumbCont.y = count;
                thumbCont.buttonMode = true;
                count += 8;
            }
        }
    }
}

```

I call this as file from my flash movie on a mouse over instant like this

```auto

var thumbs:thumbNail = new thumbNail(1);

```

The problem is that the moiveclips thumbCont are not getting added to stage. Instead I get this error -

TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at thumbNail/xmlLoaded()  
at flash.events::EventDispatcher/dispatchEventFunction()  
at flash.events::EventDispatcher/dispatchEvent()  
at [flash.net](http://flash.net)::URLLoader/onComplete()  
out

The culprit is this line of code from what I figure out - stageRef.addChild(thumbCont);

Am I not referring to the stage of the flash movie (the one that is calling this action script) properly. What am I doing wrong? Please Help.
