2017-07-03 86 views
0

我收到错误#1009,但我不知道为什么。我从线31得到的错误,而12以下是代码:从函数中获取错误1009?

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版本的灯。谢谢。

回答

3

的问题是在这里:

startGenerate(); 

var randomArray: Array = []; 

你应该调用需要它,而不是之后该功能之前初始化randomArray