我正在開發Flash中的拼圖遊戲。我正在開發一款拼圖遊戲。給出的PuzzlePiece類的代碼如下。TypeError:在Actionscript 3中出現錯誤#1009
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class PuzzlePiece extends MovieClip
{
private var pieceX:Number;
private var pieceY:Number;
private var pieceXRandom:Number;
private var pieceYRandom:Number;
public function PuzzlePiece(pieceXRandom:Number,pieceYRandom:Number)
{
this.pieceXRandom = pieceXRandom;
this.pieceYRandom = pieceYRandom;
this.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
positionClips();
this.gotoAndStop(2);
this.holder_mc.width = this.holder_mc.height = 60;
this.mask1_mc.width = this.mask2_mc.width = 60;
this.mask1_mc.height = this.mask2_mc.height = 60;
}
private function positionClips():void
{
this.x = pieceXRandom;
this.y = pieceYRandom;
}
private function Drag(e:MouseEvent)
{
switch (e.type)
{
case 'mouseDown' :
this.startDrag();
this.addEventListener(MouseEvent.MOUSE_UP,Drag);
break;
case 'mouseUp' :
this.stopDrag();
this.removeEventListener(MouseEvent.MOUSE_UP,Drag);
/*var m:*=this.parent;
m.pos(this.x,this.y);*/
}
}
}
}
這是主時間軸中的代碼。
//Global variables//
var imageDimension:Number = 360;
var gridType:Number = 6;
var puzzlePieceShape:String = "Sqaure";
var imageLoader:Loader = new Loader();
var bitmapArray:Array = [];
var puzzlePiece:PuzzlePiece;
var bitmapManip:BitmapManipulation;
loadImage();
function loadImage()
{
imageLoader.load(new URLRequest("Mohanlal.jpg"));//The image being loaded is of 360*360
imageHolder_mc.addChild(imageLoader);//imageHolder_mc is an empty MovieClip on stage
imageHolder_mc.visible = false;
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, layoutPieces);
}
function layoutPieces(evt:Event)
{
bitmapManip = new BitmapManipulation(imageDimension,gridType);
bitmapArray = bitmapManip.getBitmapImagePieces(imageHolder_mc);
for (var j:uint =0; j<bitmapArray.length; j++)
{
for (var k:uint=0; k<bitmapArray[j].length; k++)
{
var bitmap:Bitmap = new Bitmap(bitmapArray[j][k]);
puzzlePiece = new PuzzlePiece(400 * Math.random(),400 * Math.random());
addChild(puzzlePiece);
puzzlePiece.holder_mc.addChild(bitmap);
}
}
}
位圖操作類
package
{
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
public class BitmapManipulation extends MovieClip
{
private var imageDimension:Number;
private var gridDimension:Number;
public function BitmapManipulation(imageDimension:Number,gridDimension:Number)
{
this.imageDimension = imageDimension;
this.gridDimension = gridDimension;
}
public function getBitmapImagePieces(imageMC:MovieClip):Array
{
var bitmapArray:Array = [];
var imageBitmapData:BitmapData = new BitmapData(imageMC.width,imageMC.height);
imageBitmapData.draw(imageMC);
var tileDimesion:Number = this.imageDimension/this.gridDimension;
for (var i:uint = 0; i<this.gridDimension; i++)
{
bitmapArray[i] = new Array();
for (var j:uint = 0; j<this.gridDimension; j++)
{
var tempData:BitmapData = new BitmapData(tileDimesion,tileDimesion);
var tempRect:Rectangle = new Rectangle(((tileDimesion) * i),((tileDimesion) * j),tileDimesion,tileDimesion);
tempData.copyPixels(imageBitmapData,tempRect,new Point(0,0));
bitmapArray[i][j] = tempData;
}
}
return(bitmapArray);
}
}
}
的puzzlepiece的movieclip具有兩層
Mask Layer - Two masks. One rectangular and one triangular in frame 1 and 2.
Holder Layer - holder_mc
我試圖設置使用PuzzlePiece類的代碼拼圖內的movieclip的尺寸。
但我得到這個錯誤。
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PuzzlePiece()[C:\Users\Shabeeb\Desktop\Puzzle OOP\PuzzlePiece.as:26]
at PuzzlePiece_fla::MainTimeline/layoutPieces()[PuzzlePiece_fla.MainTimeline::frame1:33]
Line number 33 in main timeline class calls
this.holder_mc.width = this.holder_mc.height = 60;
this.mask1_mc.width = this.mask2_mc.width = 60;
this.mask1_mc.height = this.mask2_mc.height = 60;
訪問它是否是錯誤的。 PuzzlePiece是拼圖夾子的出口。
目前我很難將尺寸編碼爲60.我有aloso上傳fla和作爲文件。
https://rapidshare.com/files/4248268633/Puzzle_OOP.zip
你的口罩是否存在於第1幀? – Kodiak
編號holder_mc和mask1_mc在frame1上。 mask2_mc在frame2上。 –
在另一個論壇中發佈了相同的問題。這是發生在那裏的討論。 http://www.kirupa.com/forum/showthread.php?367987 - 從關聯文檔類父級設置嵌套剪輯的屬性 –