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