从函数获取错误 1009?



我收到错误 #1009,但我不知道为什么。我从第 31 行和第 12 行收到错误。这是代码:

import flash.events.MouseEvent;
var TLBool: Boolean = false;
var TBool: Boolean = false;
var TRBool: Boolean = false;
var CLBool: Boolean = false;
var CBool: Boolean = false;
var CRBool: Boolean = false;
var BLBool: Boolean = false;
var BBool: Boolean = false;
var BRBool: Boolean = false;
startGenerate();
var randomArray: Array = [];
var buttonPressed: String;
TL.addEventListener(MouseEvent.CLICK, TLClick);
T.addEventListener(MouseEvent.CLICK, TClick);
TR.addEventListener(MouseEvent.CLICK, TRClick);
CL.addEventListener(MouseEvent.CLICK, CLClick);
C.addEventListener(MouseEvent.CLICK, CClick);
CR.addEventListener(MouseEvent.CLICK, CRClick);
BL.addEventListener(MouseEvent.CLICK, BLClick);
B.addEventListener(MouseEvent.CLICK, BClick);
BR.addEventListener(MouseEvent.CLICK, BRClick);
//mix
function startGenerate() {
randomArray[0] = Math.floor(Math.random() * 2);
randomArray[1] = Math.floor(Math.random() * 2);
randomArray[2] = Math.floor(Math.random() * 2);
randomArray[3] = Math.floor(Math.random() * 2);
randomArray[4] = Math.floor(Math.random() * 2);
randomArray[5] = Math.floor(Math.random() * 2);
randomArray[6] = Math.floor(Math.random() * 2);
randomArray[7] = Math.floor(Math.random() * 2);
randomArray[8] = Math.floor(Math.random() * 2);
trace(randomArray.join());
if (randomArray[0] == 1) {
TLBool = true;
TL.gotoAndStop(2);
} else {
TLBool = false;
TL.gotoAndStop(1);
}
if (randomArray[1] == 1) {
TBool = true;
T.gotoAndStop(2);
} else {
TBool = false;
T.gotoAndStop(1);
}
if (randomArray[2] == 1) {
TRBool = true;
TR.gotoAndStop(2);
} else {
TRBool = false;
TR.gotoAndStop(1);
}
if (randomArray[3] == 1) {
CLBool = true;
CL.gotoAndStop(2);
} else {
CLBool = false;
CL.gotoAndStop(1);
}
if (randomArray[4] == 1) {
CBool = true;
C.gotoAndStop(2);
} else {
CBool = false;
C.gotoAndStop(1);
}
if (randomArray[5] == 1) {
CRBool = true;
CR.gotoAndStop(2);
} else {
CRBool = false;
CR.gotoAndStop(1);
}
if (randomArray[6] == 1) {
BLBool = true;
BL.gotoAndStop(2);
} else {
BLBool = false;
BL.gotoAndStop(1);
}
if (randomArray[7] == 1) {
BBool = true;
B.gotoAndStop(2);
} else {
BBool = false;
B.gotoAndStop(1);
}
if (randomArray[8] == 1) {
BRBool = true;
BR.gotoAndStop(2);
} else {
BRBool = false;
BR.gotoAndStop(1);
}
}
//Corners
function TLClick(event: MouseEvent) {
if (!TLBool) {
TLBool = true;
TL.gotoAndStop(2);
} else {
TLBool = false;
TL.gotoAndStop(1);
}
if (!CLBool) {
CLBool = true;
CL.gotoAndStop(2);
} else {
CLBool = false;
CL.gotoAndStop(1);
}
if (!TBool) {
TBool = true;
T.gotoAndStop(2);
} else {
TBool = false;
T.gotoAndStop(1);
}
}

function TRClick(event: MouseEvent) {
if (!TRBool) {
TRBool = true;
TR.gotoAndStop(2);
} else {
TRBool = false;
TR.gotoAndStop(1);
}
if (!CRBool) {
CRBool = true;
CR.gotoAndStop(2);
} else {
CRBool = false;
CR.gotoAndStop(1);
}
if (!TBool) {
TBool = true;
T.gotoAndStop(2);
} else {
TBool = false;
T.gotoAndStop(1);
}
}
function BRClick(event: MouseEvent) {
if (!BRBool) {
BRBool = true;
BR.gotoAndStop(2);
} else {
BRBool = false;
BR.gotoAndStop(1);
}
if (!CRBool) {
CRBool = true;
CR.gotoAndStop(2);
} else {
CRBool = false;
CR.gotoAndStop(1);
}
if (!BBool) {
BBool = true;
B.gotoAndStop(2);
} else {
BBool = false;
B.gotoAndStop(1);
}
}
function BLClick(event: MouseEvent) {
if (!BLBool) {
BLBool = true;
BL.gotoAndStop(2);
} else {
BLBool = false;
BL.gotoAndStop(1);
}
if (!CLBool) {
CLBool = true;
CL.gotoAndStop(2);
} else {
CLBool = false;
CL.gotoAndStop(1);
}
if (!BBool) {
BBool = true;
B.gotoAndStop(2);
} else {
BBool = false;
B.gotoAndStop(1);
}
}
//edges
function TClick(event: MouseEvent) {
if (!TBool) {
TBool = true;
T.gotoAndStop(2);
} else {
TBool = false;
T.gotoAndStop(1);
}
if (!TRBool) {
TRBool = true;
TR.gotoAndStop(2);
} else {
TRBool = false;
TR.gotoAndStop(1);
}
if (!TLBool) {
TLBool = true;
TL.gotoAndStop(2);
} else {
TLBool = false;
TL.gotoAndStop(1);
}
if (!CBool) {
CBool = true;
C.gotoAndStop(2);
} else {
CBool = false;
C.gotoAndStop(1);
}
}
function CLClick(event: MouseEvent) {
if (!CLBool) {
CLBool = true;
CL.gotoAndStop(2);
} else {
CLBool = false;
CL.gotoAndStop(1);
}
if (!TLBool) {
TLBool = true;
TL.gotoAndStop(2);
} else {
TLBool = false;
TL.gotoAndStop(1);
}
if (!BLBool) {
BLBool = true;
BL.gotoAndStop(2);
} else {
BLBool = false;
BL.gotoAndStop(1);
}
if (!CBool) {
CBool = true;
C.gotoAndStop(2);
} else {
CBool = false;
C.gotoAndStop(1);
}
}
function CRClick(event: MouseEvent) {
if (!CRBool) {
CRBool = true;
CR.gotoAndStop(2);
} else {
CRBool = false;
CR.gotoAndStop(1);
}
if (!TRBool) {
TRBool = true;
TR.gotoAndStop(2);
} else {
TRBool = false;
TR.gotoAndStop(1);
}
if (!BRBool) {
BRBool = true;
BR.gotoAndStop(2);
} else {
BRBool = false;
BR.gotoAndStop(1);
}
if (!CBool) {
CBool = true;
C.gotoAndStop(2);
} else {
CBool = false;
C.gotoAndStop(1);
}
}
function BClick(event: MouseEvent) {
if (!BBool) {
BBool = true;
B.gotoAndStop(2);
} else {
BBool = false;
B.gotoAndStop(1);
}
if (!BRBool) {
BRBool = true;
BR.gotoAndStop(2);
} else {
BRBool = false;
BR.gotoAndStop(1);
}
if (!BLBool) {
BLBool = true;
BL.gotoAndStop(2);
} else {
BLBool = false;
BL.gotoAndStop(1);
}
if (!CBool) {
CBool = true;
C.gotoAndStop(2);
} else {
CBool = false;
C.gotoAndStop(1);
}
}
//Center
function CClick(event: MouseEvent) {
if (!CBool) {
CBool = true;
C.gotoAndStop(2);
} else {
CBool = false;
C.gotoAndStop(1);
}
if (!TBool) {
TBool = true;
T.gotoAndStop(2);
} else {
TBool = false;
T.gotoAndStop(1);
}
if (!CLBool) {
CLBool = true;
CL.gotoAndStop(2);
} else {
CLBool = false;
CL.gotoAndStop(1);
}
if (!CRBool) {
CRBool = true;
CR.gotoAndStop(2);
} else {
CRBool = false;
CR.gotoAndStop(1);
}
if (!BBool) {
BBool = true;
B.gotoAndStop(2);
} else {
BBool = false;
B.gotoAndStop(1);
}
}

问题来自这里:(第 31 行(

function startGenerate() {
randomArray[0] = Math.floor(Math.random() * 2); //This is line 31
randomArray[1] = Math.floor(Math.random() * 2);
randomArray[2] = Math.floor(Math.random() * 2);
randomArray[3] = Math.floor(Math.random() * 2);
randomArray[4] = Math.floor(Math.random() * 2);
randomArray[5] = Math.floor(Math.random() * 2);
randomArray[6] = Math.floor(Math.random() * 2);
randomArray[7] = Math.floor(Math.random() * 2);
randomArray[8] = Math.floor(Math.random() * 2);
trace(randomArray.join());
if (randomArray[0] == 1) {
TLBool = true;
TL.gotoAndStop(2);
} else {
TLBool = false;
TL.gotoAndStop(1);
}
if (randomArray[1] == 1) {
TBool = true;
T.gotoAndStop(2);
} else {
TBool = false;
T.gotoAndStop(1);
}
if (randomArray[2] == 1) {
TRBool = true;
TR.gotoAndStop(2);
} else {
TRBool = false;
TR.gotoAndStop(1);
}
if (randomArray[3] == 1) {
CLBool = true;
CL.gotoAndStop(2);
} else {
CLBool = false;
CL.gotoAndStop(1);
}
if (randomArray[4] == 1) {
CBool = true;
C.gotoAndStop(2);
} else {
CBool = false;
C.gotoAndStop(1);
}
if (randomArray[5] == 1) {
CRBool = true;
CR.gotoAndStop(2);
} else {
CRBool = false;
CR.gotoAndStop(1);
}
if (randomArray[6] == 1) {
BLBool = true;
BL.gotoAndStop(2);
} else {
BLBool = false;
BL.gotoAndStop(1);
}
if (randomArray[7] == 1) {
BBool = true;
B.gotoAndStop(2);
} else {
BBool = false;
B.gotoAndStop(1);
}
if (randomArray[8] == 1) {
BRBool = true;
BR.gotoAndStop(2);
} else {
BRBool = false;
BR.gotoAndStop(1);
}
}

第 12 行:

startGenerate();

我想我可能会从函数中得到错误,这是不寻常的。TL、T、TR、CL、C、CR、BL、B 和 BR 都是电影剪辑中的实例名称,所以我知道这不是问题。我的 Flash 项目只有一个帧,我刚才提到的影片剪辑是舞台上唯一的对象。我删除了startGenerate((函数,它工作得很好。我正在制作一个 3x3 版本的熄灯。谢谢。

问题就在这里:

startGenerate();
var randomArray: Array = [];

你应该在调用需要它的函数之前初始化randomArray,而不是之后。