# Cannot access a property or method of a null object reference error

**URL:** https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference-error/303155
**Category:** flash
**Created:** [January 15, 2010, 1:07am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference-error/303155 "2010-01-15T01:07:57Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![hokeyplyr48](https://avatars.discourse-cdn.com/v4/letter/h/91b2a8/32.png) [@hokeyplyr48](https://forum.kirupa.com/u/hokeyplyr48)
#### Post date: [January 15, 2010, 1:07am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference-error/303155/1 "2010-01-15T01:07:57Z")

</div>

I have a my project that has three frames on the main timeline.  
Frame Label MovieClip Instance Name Class file  
Intro\_Frame -\> Intro\_symbol -\> Intro\_Page  
Content\_Page -\> Content\_symbol -\> Content  
Credits\_Page -\> Credits\_symbol -\> Credits

My plan : I have buttons on the bottom of each page. One on the intro page, two on the Content page (to go back to intro and to go to the credits page) and one on my Credits page to go back to the content.

My Intro page has everything physically on the stage, and my other two pages have everything dynamically instantiated. For some reason all of the objects when I put a trace(MovieClip(this.parent)) it always prints out null but for the objects in my intro page that are physically put on the stage, it prints out the parent just fine.

I have a transition from my intro page to my content page in actual tweens on the timeline and have given it a label. But for some reason I can’t access it because none of my dynamic things have parent names.

Graphically it’s as follows:

I’m at button on credits -\> go to parent Credits -\> go to parents Card (class / container movieclip that holds everything) -\> back down to Intro\_symbol -\> gotoAndPlay(“Transition2”);

It always returns an error saying “cannot access a property or method of a null object reference”

Any ideas?

I’ve uploaded the code for you to take a look at.

Right now I have it so that on the beginning frame, the card class (the container) adds the Intro\_symbol as a child. It works fine, then when you click the button it moves it to the transition frame on the timeline in the Intro\_symbol. It plays fine till it moves the the frame at the end labeled “gotocontent”.

I have an addEventListener(Event.ENTER\_FRAME, enterFrameHandler) then if(currentFrame == “gotocontent”) it moves the main timeline in the Card object to “Content\_Page”.

It gets to that page but when I have the same setup in the card class involving action listeners to the if(currentFrame == “Content\_Page”) and then it creates the content symbol Content\_symbol = new Content() it throws the “Cannot access a propery or method of a null object reference”.

Intro\_Page class

```auto
package classes
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.Timer;
    
    public class Intro_Page extends MovieClip
    {
        var peopleDelay;
        public function Intro_Page()
        {
            peopleDelay = new Timer(800);
            peopleDelay.addEventListener("timer", timerHandler);
            this.addEventListener(Event.ENTER_FRAME,enterFrame_handler);
        }
        public function enterFrame_handler(e:Event):void
        {
            if(currentLabel == "Intro")
            {
                people.stop();
                peopleDelay.start();
            }
            else if(currentFrameLabel == "GoToContent")
            {
                trace("goto content if statement in Intro_Page");
                //this.stop();
                this.removeEventListener(Event.ENTER_FRAME,enterFrame_handler);
                Card(this.parent).gotoAndStop("Content_Page");
            }
        }
        
        function timerHandler(e:Event):void
        {
            peopleDelay.reset();
            people.gotoAndPlay("walking");
        }
    }
}

```

Card class

```auto
package classes
{
    import flash.display.*;
    import flash.events.*;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent;
    import flash.utils.Timer;
    
    public class Card extends MovieClip
    {        
        public var Intro_symbol:Intro_Page;
        public var Content_symbol:Content;
        public var Credits_symbol:Credits;
        public var introBoolean=true;
        public var contentBoolean=true;
        
        public function Card()
        {
            
            this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
        }
        public function enterFrameHandler(e:Event)
        {
            //Content_symbol = new Content();
            //Credits_symbol = new Credits();
            if(currentFrameLabel == "Intro_Frame" && introBoolean == true)
            {
                introBoolean = false;
                trace("Adding intro to stage");
                Intro_symbol = new Intro_Page();
                this.addChild(Intro_symbol);
                trace("from card to intro: " + this.Intro_symbol);
                Intro_symbol.x=399.1;
                Intro_symbol.y=300.6;
            }
            if(currentFrameLabel == "Content_Page" && contentBoolean == true)
            {
                contentBoolean = false;
                trace("Adding content to stage");
                Content_symbol = new Content(); //THIS LINE RIGHT HERE IF IT IS ALLOWED TO RUN THROWS THE ERROR
                //this.addChild(Content_symbol);
                //Content_symbol.x=0;
                //Content_symbol.y=0;
            }            
        }
    }
}

```

Here’s all my files. I would have uploaded them here but the zip file is 200k to big.  
[http://www.megaupload.com/?d=PWC17XI5](http://www.megaupload.com/?d=PWC17XI5)
