Hi there,
I am still very new to OOP and writing custom classes. Learning alot as I am going along. I am trying to write a simple preloader class. My question in my constructor function I call the drawshape() method as code below shows:
package
{
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
public class Preloader extends MovieClip
{
var _shape:Shape;
public function Preloader()
{
drawShape();
}
private function drawShape():void
{
_shape = new Shape();
_shape.graphics.lineStyle(2,0xff0000);
_shape.graphics.beginFill(0x00ff00);
_shape.graphics.drawRect(stage.stageWidth/2 , stage.stageHeight/2, 20, 30);
_shape.graphics.endFill();
addChild(_shape);
}
}
}
on my timeline frame 1 I create an instance of the class:
var loader:Preloader = new Preloader();
When running the movie I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Preloader/::drawShape()
at Preloader$iinit()
at loader_fla::MainTimeline/loader_fla::frame1()
I understand that the onject has not been created when I call it, but what do I do to prevent this? I am still very new at AS3, and it has scared me since release. :);(
Thanks