I'm not sure what I'm missing I can't find anything wrong. Eclipse isn't showing any errors but when I run in Flash I get the following error.
I have 3 classes The Main being CoreyDouglas where I am initiating a new background which extends my page class.TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AS::Page()
at AS::Background()
at CoreyDouglas()
the 3 classes look like this:
CoreyDouglas:
background:Code:package { import AS.Background; import flash.display.Sprite; public class CoreyDouglas extends Sprite { private var background:Background; public function CoreyDouglas() { background = new Background("images/background"); this.addChildAt(background, 0); } } }
and the Page ClassCode:package AS { import flash.display.Bitmap; import flash.display.Loader; import flash.events.Event; import flash.net.URLRequest; public class Background extends Page { private var bgsrc:String; private var loader:Loader; private var bg:Bitmap; private var bgWidth:Number; private var bgHeight:Number; public function Background(src:String) { super(); bgsrc = src; } override protected function init(e:Event):void { loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete); loader.load(new URLRequest(bgsrc)); } private function onLoadComplete(e:Event):void { bg = new Bitmap(e.currentTarget.content); bg.smoothing = true; bgHeight = bg.height / bg.width; bgWidth = bg.width / bg.height; if ((stage.stageHeight / stage.stageWidth) < bgHeight) { bg.width = stage.stageWidth; bg.height = bgHeight * bg.width; } else { bg.height = stage.stageHeight; bg.width = bgWidth * bg.height; } addChild(bg); } } }
This is probably something extremely simple that I can't see. Thanks for your help I appreciate it.Code:package AS { import flash.display.Sprite; import flash.events.Event; public class Page extends Sprite { public function Page() { super(); this.addEventListener(Event.ADDED_TO_STAGE, init); stage.addEventListener(Event.RESIZE, onStageResize); } protected function init(e:Event):void {}; protected function onStageResize(e:Event):void {}; } }





Bookmarks