Code:
package {
	import flash.display.*;
	import flash.events.*;

	public class matchgame extends MovieClip {
		private static const boardWidth:uint=6;
		private static const boardHeight:uint=6;
		private static const cardHorizontalSpacing:Number=52;
		private static const cardVerticalSpacing:Number=52;
		private static const boardOffsetX:Number=120;
		private static const boardOffsetY:Number=45;
		private var firstCard:Card;
		private var secondCard:Card;
		private var cardsleft:uint;

		public function clickCard(e:MouseEvent) {
			var thisCard:Card = (e.currentTarget as Card);
			if (firstCard==null) {
				firstCard=thisCard;
				firstCard.gotoAndStop(thisCard.cardface+2);
			} else if (firstCard == thisCard) {
				firstCard.gotoAndStop(1);
				firstCard=null;
			} else if (secondCard == null) {
				secondCard=thisCard;
				secondCard.gotoAndStop(thisCard.cardface+2);
			}
			if (firstCard.cardface==secondCard.cardface) {
				removeChild(firstCard);
				removeChild(secondCard);
				firstCard=null;
				secondCard=null;
				cardsleft-=2;
				if (cardsleft==0) {
					gotoAndStop("gameover");
				}
			} else {
				firstCard.gotoAndStop(1);
				secondCard.gotoAndStop(1);
				secondCard=null;
				firstCard=thisCard;
				firstCard.gotoAndStop(thisCard.cardface + 2);
			}
		}

		public function matchgame():void {
			var cardlist:Array = new Array();
			for (var i:uint=0; i<boardWidth*boardHeight/2; i++) {
				cardlist.push(i);
				cardlist.push(i);
			}
			cardsleft=0;
			for (var x:uint=0; x<boardWidth; x++) {
				for (var y:uint=0; y<boardHeight; y++) {
					var c:Card = new Card();
					c.height=50;
					c.width=50;
					c.stop();
					c.x=x*cardHorizontalSpacing+boardOffsetX;
					c.y=y*cardVerticalSpacing+boardOffsetY;
					var r:uint=Math.floor(Math.random()*cardlist.length);
					c.cardface=cardlist[r];
					cardlist.splice(r,1);
					addChild(c);
					c.addEventListener(MouseEvent.CLICK, clickCard);
					cardsleft++;
				}
			}
		}
	}
}
here is my AS3 script... very simple matching game... works fine, just only it gives error: "TypeError: Error #1009: Cannot access a property or method of a null object reference. at matchgame/clickCard()"