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

**URL:** https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/289488
**Category:** Uncategorized
**Created:** [May 31, 2009, 2:47pm UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/289488 "2009-05-31T14:47:26Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![szox](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@szox](https://forum.kirupa.com/u/szox)
#### Post date: [May 31, 2009, 2:47pm UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/289488/1 "2009-05-31T14:47:26Z")

</div>

Hi,

I have problem with accessing object created by function imported from another package.  
I have 2 packages DragDrop and UserInterface. In UserInterface I create methods for buttons and later add them in DragDrop . I make it in two different ways:  
One(this one works):

```auto

//UserInput

public var wSubmitBtn:Button;
     
   public function wSetupButton():void {
            
            wSubmitBtn = new Button();
            wSubmitBtn.move(700,100);
            wSubmitBtn.label = "Create";
            wSubmitBtn.enabled = false;
            wSubmitBtn.setSize(50,20);
            
            addChild(wSubmitBtn);
        }

//Dragdrop
private var iUI:UserInterface = new UserInterface;
private function submitLogin(e:MouseEvent):Array {

//iUI 
                iUI.wSetupButton();
                iUI.wSubmitBtn.addEventListener(MouseEvent.CLICK, create);

..}

```

I wrote method to make adding new elements easy but i cant access objects created inside this method. Object itself is created but there seems to be no reference to it.

```auto

//UserInput

public var wSubmitBtn:Button;

public function buttonMaker(button:Button, btnName:String, offset:Number):void {
            
            button = new Button();
            button.move(menuX,menuY+offset);
            button.label = btnName;
            button.enabled = true;
            button.setSize(menuW,menuH);
            
            trace(addChild(button));
        }

//Dragdrop
private var iUI:UserInterface = new UserInterface;

private function submitLogin(e:MouseEvent):Array {

iUI.buttonMaker(iUI.wSubmitBtn,"submit",44); // button is created without problems
**iUI.wSubmitBtn.addEventListener(MouseEvent.CLICK, remCan); //this line throws an error
//Cannot access a property or method of a null object reference.**

..}

```

I tried different ways to access it but none of them worked. How to solve this problem?
