# addChild(topBlock); - but cant find topBlock

**URL:** <https://forum.kirupa.com/t/addchild-topblock-but-cant-find-topblock/298097>\
**Category:** flash\
**Created:** [October 13, 2009, 5:39pm UTC](https://forum.kirupa.com/t/addchild-topblock-but-cant-find-topblock/298097 "2009-10-13T17:39:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalseide](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@dalseide](https://forum.kirupa.com/u/dalseide)\
**Post date:** [October 13, 2009, 5:39pm UTC](https://forum.kirupa.com/t/addchild-topblock-but-cant-find-topblock/298097/1 "2009-10-13T17:39:32Z")

</div>

Hi, I’m a rookie in OOP but I’m trying to learn.  
Right now I can’t figure out why I cant target the sprite topBlock created like this:

```auto

//DynHeader.as
package classes.framework {
    import flash.display.Sprite;
    import flash.display.Graphics;
    import flash.events.Event;
    import Main;
        
    public class DynHeader extends Sprite {
        
        public var _headerHeight:Number;
        public var _headerColour:String;
        
        public function DynHeader(_headerHeight, _headerColour) {
            
            construct();
            function construct() {
            var topBlock:Sprite = new Sprite();
            var gr:Graphics = topBlock.graphics;
            gr.lineStyle();
            gr.beginFill(_headerColour, 1.0);
            gr.drawRect(0,0,Main.stage.stageWidth,_headerHeight);
            gr.endFill();
            topBlock.x = 0;
            topBlock.y = 0;
            addChild(topBlock);
            }
            
            topBlock.x = 30;
            
            
        }
    }
}

```

The message I get from the compiler is:

```auto

1120: Access of undefined property topBlock. | topBlock.x = 30;

```

Without the line “topBlock.x = 30;” everything is working smoothly.

(After searching around it might be that I have misunderstood how “addChild” and “var topBlock:Sprite = new Sprite();” works).

I’m going to add a function so the width is going to change whenever the stage changes. But first I need to find out how to target topBlock, or whatever my rectangle is named.
