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

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):


//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.


//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?