Hi all,
I know there’s a few threads on this subject, but unfortunately those didn’t help me out too much. Also read the live docs on this and have gotten nowhere.
So here’s my code:
classes/RssRead.as
package classes {
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageScaleMode;
import classes.graphics.*;
public class RssRead extends Sprite {
private var _bg:Background;
public function RssRead() {
init();
}
private function init():void {
initStage();
fireBackground();
}
private function initStage():void {
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
private function fireBackground():void {
_bg = new Background(0x333333);
addChild(_bg);
}
}
}
classes/graphics/Background.as
package classes.graphics {
import flash.display.Sprite;
import flash.display.Graphics;
public class Background extends Sprite {
private var _color:uint;
public function Background(c:uint) {
_color = c;
init();
}
private function init():void {
drawBackground();
}
private function drawBackground():void {
graphics.beginFill(_color);
graphics.drawRect(0, 0, stage.height, stage.width);
graphics.endFill();
}
}
}
errors:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at classes.graphics::Background/::drawBackground()
at classes.graphics::Background/::init()
at classes.graphics::Background$iinit()
at classes::RssRead/::fireBackground()
at classes::RssRead/::init()
at classes::RssRead$iinit()
I understand basically what the error is saying. I’m trying to apply changes to objects which are null. However I don’t really understand this issue because I’ve run code almost identical to this before without any issues. Any thoughts would be great, it’s frustrating trying to build code and getting stuck this early in the game every time :-/