addChild(topBlock); - but cant find topBlock

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:

package classes.framework {
    import flash.display.Sprite;
    import flash.display.Graphics;
    import Main;
    public class DynHeader extends Sprite {
        public var _headerHeight:Number;
        public var _headerColour:String;
        public function DynHeader(_headerHeight, _headerColour) {
            function construct() {
            var topBlock:Sprite = new Sprite();
            var gr:Graphics =;
            gr.beginFill(_headerColour, 1.0);
            topBlock.x = 0;
            topBlock.y = 0;
            topBlock.x = 30;

The message I get from the compiler is:

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.