so it’s basic.. I need this bitmap to save the red square image into an array… but it’s showing me that I am accessing an unidentified method or property… this is more or less my first time with array’s and I saw a bunch of tuts on hw to use them and for what and I think this is how they pointed to assign them to something..so please if I am doing something wrong can somebody tell me..I am just trying to learn how they work by trying them out…
var myImages:Array;
red_square.addEventListener( MouseEvent.CLICK, firstchoice);
function firstchoice (e:MouseEvent){
finalsave.redsquare = 1;
myImages[0] = new BitmapData(151, 167);
bitmap = new Bitmap (myImages[0]);
addChild(bitmap);
myImages[0].draw (red_square);
gotoAndPlay(5);
stop();
};
the error I get is
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at gamefile_fla::MainTimeline/firstchoice()[gamefile_fla.MainTimeline::frame4:13]
Your array starts off empty, so when you try and access position zero it gets confused. Instead of using this line of code:
myImages[0] = new BitmapData(151, 167);use
myImages.push(new BitmapData(151, 167));The push command will add an element to the end of an array, so the size will increase by 1. Now you are safe to use
myImages[0].draw(red_square);.Also when you declare your array variable,
var myImages:Arrayit’s good practice to initialize it, either in a constructor or some method, so change it tovar myImages:Array = new Array();.