# 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/235204>\
**Category:** flash\
**Created:** [August 9, 2007, 9:41am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/235204 "2007-08-09T09:41:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcanistrum](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jcanistrum/32/2188_2.png) [@jcanistrum](https://forum.kirupa.com/u/jcanistrum)\
**Post date:** [August 9, 2007, 9:41am UTC](https://forum.kirupa.com/t/cannot-access-a-property-or-method-of-a-null-object-reference/235204/1 "2007-08-09T09:41:55Z")

</div>

Hi All,

I´m stucked with “Cannot access a property or method of a null object reference”

I did a small test inside the IDE and it works fine

```php
 
var _container:Sprite;
var holder:Sprite = new Sprite();
addChild( holder );
 
PainelNumeros( holder );
function PainelNumeros(mc:Sprite)
{
 _container = new Sprite();
 draw();
 mc.addChild(_container);
}
function draw():void
{
 var origX = 23;
 var origY = 126.5;
 var deltaX = 24.5;
 var deltaY = 17.9;
 var larguraBox = 17.8;
 var alturaBox = 9.4;
 var posX = origX;
 var posY = origY;
 var elemento = 0;
 for (var i = 1; i <= 10; i++)
 {
  for (var j = 1; j <= 10; j++)
  {
   var nome = "numero" + elemento ; 
   _container.addChild( new SpriteBox() ).name = nome;
   _container.getChildByName( nome ).x = posX;
   _container.getChildByName( nome ).y = posY;
   _container.getChildByName( nome ).width = larguraBox;
   _container.getChildByName( nome ).height = alturaBox;
   _container.getChildByName( nome ).alpha = 0.5;
   _container.getChildByName( nome ).addEventListener(MouseEvent.CLICK, mouseClickHandler);
   posX += deltaX;
   elemento++;
  }
  posX = origX;
  posY += deltaY;
 }
}
function mouseClickHandler(event:MouseEvent)
{
 trace( event.target.parent.name );
}
................................................................
package 
{
 import flash.display.*;
 import flash.events.*;
 public class SpriteBox extends Sprite
 {
  private var size:uint = 50 ;
  private var status:Boolean;
  private var bgColor:uint = 0xFFCC00;
  public function SpriteBox()
  {
   var child:Sprite = new Sprite();
   status = false;
   draw(child);
            addChild(child);
  }
  private function draw(sprite:Sprite):void
  {
   sprite.graphics.beginFill(bgColor);
   sprite.graphics.drawRect(0, 0, size, size);
   sprite.graphics.endFill();
  }
 }
}

```

Then I tryed to translate what I got through the IDE to a new class

```php
 
package 
{
 import flash.display.*;
 import flash.events.*;
 public class PainelNumeros
 {
  private var _container:Sprite;
  public function PainelNumeros(mc:Sprite)
  {
   var _container:Sprite = new Sprite();
   draw();
   mc.addChild(_container);
  }
  private function draw():void
  {
   var origX = 23;
   var origY = 126.5;
   var deltaX = 24.5;
   var deltaY = 17.9;
   var larguraBox = 17.8;
   var alturaBox = 9.4;
   var posX = origX;
   var posY = origY;
   var elemento = 0;
   for (var i = 1; i <= 10; i++)
   {
    for (var j = 1; j <= 10; j++)
    {
     var marca:SpriteBox = new SpriteBox();
     var nome = "numero" + elemento;
     _container.addChild( new SpriteBox() ).name = nome;
     _container.getChildByName( nome ).x = posX;
     _container.getChildByName( nome ).y = posY;
     _container.getChildByName( nome ).width = larguraBox;
     _container.getChildByName( nome ).height = alturaBox;
     _container.getChildByName( nome ).alpha = 0.5;
     _container.getChildByName(nome).addEventListener(MouseEvent.CLICK, mouseClickHandler);
     posX += deltaX;
     elemento++;
    }
    posX = origX;
    posY += deltaY;
   }
  }
  private function mouseClickHandler(event:MouseEvent)
  {
   trace( event.target.parent.name );
  }
 }
}

```

and tryed to instantiate it in the IDE

```php
 
var holder:Sprite = new Sprite();
addChild( holder ) ;
 
var painel1:PainelNumeros = new PainelNumeros ( holder ) ;

```

Where I get the error, what am I doing wrong ?

thanks in advance

jcarlos
