I cant load an image in the document class.
Do I need to load all images from a class as I cant load images in a Document class directly?
With this code I get a
Error #1009: Cannot access a property or method of a null object reference.
at Main/moveright()
at Main/doSomething()
// Class public class Main extends MovieClip { // Variables private var noLoaded:int; var myText:TextField = new TextField(); private var img1:Bitmap; // Constructor public function Main():void { // Stage set up stage.align=StageAlign.TOP_LEFT; stage.scaleMode=StageScaleMode.NO_SCALE; stage.quality=StageQuality.BEST; stage.displayState=StageDisplayState.NORMAL; stage.frameRate=30; // Init load counter noLoaded=0; // Create a ClassImg6 instance // Add stage listeners stage.addEventListener(Event.ENTER_FRAME,gameLoop,false,0,true); stage.addEventListener(KeyboardEvent.KEY_DOWN,doSomething,false,0,true); myText.text = "The quick brown fox jumps over the lazy dog"; addChild(myText); myText.border = true; myText.wordWrap = true; myText.width = 150; myText.height = 40; myText.x = 200; myText.y = 10; var loader:Loader = new Loader; loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); loader.load(new URLRequest("scave4.png")); } private function imageLoaded(event:Event):void { var img1:Bitmap = new Bitmap(event.target.content.bitmapData); //img1.bitmapData = bmd; addChild(img1); img1.y=100; img1.x=100; noLoaded++; } function moveleft() { img1.x-=5; } function moveright() { img1.x+=5; } function moveup() { img1.y-=5; } function movedown() { img1.y+=5; } function doSomething(e:KeyboardEvent):void { if (e.keyCode==37) { moveleft(); }// Left if (e.keyCode==39) { moveright(); trace("rigfht"); }// Right if (e.keyCode==38) {moveup(); }// Left if (e.keyCode==40) { movedown(); }// Right