从函数中获取错误1009?

时间:2017-07-03 05:24:02

标签: actionscript-3

我收到错误#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版本的灯。谢谢。

1 个答案:

答案 0 :(得分:3)

问题在于:

startGenerate();

var randomArray: Array = [];

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