PDA

View Full Version : null object reference



B L U E
May 3rd, 2007, 11:05 PM
i have this class

package {
import flash.display.*;
import flash.events.Event;
import flash.net.URLRequest;

public class Fullscreen extends Sprite {

private var _bg:Sprite = new Sprite(), _loader:Loader = new Loader(), url:String, _req:URLRequest;

public function Fullscreen(str:String):void {
addChild(_bg);
trace(str);
url = str;
_req = new URLRequest(url);
_loader.load(_req);
_loader.contentLoaderInfo.addEventListener(Event.C OMPLETE, imgLoaded);
}

private function onStageResize(... eventArray:Array):void {
_bgresize();
}

private function imgLoaded(evt:Event):void {
stage.frameRate = 32;
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE,onStageResize) ;
_bg.addChild(_loader.content);
_bgresize();
}

private function _bgresize():void {
_bg.width = (stage.height/stage.width > _bg.height/_bg.width) ? stage.stageHeight*(_bg.width/_bg.height) : stage.stageWidth;
_bg.height = (stage.height/stage.width > _bg.height/_bg.width) ? stage.stageHeight : stage.stageWidth*(_bg.height/_bg.width);
}
}
}

and it's outputting this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Fullscreen/::imgLoaded()

i'm pretty sure the stage values are null, but i dont know why. any ideas?

Dazzer
May 4th, 2007, 08:16 AM
you don't have a reference to stage, since it is probably not added to the display list.

If you have to do this



public function Fullscreen(str:String, s:Stage)
{
this.stageReference = s;
}


Then work with that.

B L U E
May 4th, 2007, 10:35 AM
i have to pass in a stage parameter? I thought that the Stage class was unique and could be accessed if I imported it. So would the function call look like:


var fs:Fullscreen = new Fullscreen("string", this);

or


var fs:Fullscreen = new Fullscreen("string", root);
?

senocular
May 4th, 2007, 11:41 AM
All display objects have a reference to the stage, but its null unless the display object has been added to a display list attached to the stage. If you are trying to access stage before that happens, you will need a reference to it (which can be passed into the constructor) like Dazzer said.

anielqa
October 23rd, 2008, 06:10 PM
I am using #D Mulltimedia Studio that I bought from Flashden.net and I am getting an error.
I’m having a problem loading the compiled SWF into another project. I keep getting the following error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at spaceBoard/Initial3D()
at spaceBoard()
Anyone has a possible solution for it?