AS3 - TypeError: Error #1009 "null" at MethodInfo

AS3 - TypeError: Error #1009 "null" at MethodInfo

我有这个小项目。每次单击按钮时都会改变的帧,以及箭头内的进度条的模拟。

stop();
/** initializtios **/
var trans:ColorTransform = next_arrow.transform.colorTransform;
var p:int = 1;

var myColorTransform = new ColorTransform();
myColorTransform.color = 0x42f498;
var trans1:ColorTransform = back_arrow.transform.colorTransform;

/** actual code **/
btn_next_arrow.addEventListener(MouseEvent.CLICK, function goNextLectFrame(e:MouseEvent):void {
    if (p==1) {
        fill_1.transform.colorTransform = myColorTransform;
        fill_22.alpha = 0.00001;
        fill_3.alpha = 0.00001;
        fill_33.alpha = 0.00001;
        fill_5.alpha = 0.00001;
        fill_6.alpha = 0.00001;
        fill_7.alpha = 0.00001;
        fill_8.alpha = 0.00001;
        fill_9.alpha = 0.00001;
        fill_10.alpha = 0.00001;
        fill_11.alpha = 0.00001;
        fill_12.alpha = 0.00001;
        fill_13.alpha = 0.00001;
        fill_14.alpha = 0.00001;
        fill_151.alpha = 0.00001;
        ++p;
    }
    switch (currentFrame) {
        case 1:
            gotoAndStop(2);
            break;
        case 2:
            fill_22.transform.colorTransform = myColorTransform;
            gotoAndStop(3);
            break;
        case 3:
            fill_3.transform.colorTransform = myColorTransform;
            gotoAndStop(4);
            break;
        case 4:
            fill_33.transform.colorTransform = myColorTransform;
            gotoAndStop(5);
            break;
        case 5:
            fill_5.transform.colorTransform = myColorTransform;
            gotoAndStop(6);
            break;
        case 6:
            fill_6.transform.colorTransform = myColorTransform;
            gotoAndStop(7);
            break;
        case 7:
            fill_7.transform.colorTransform = myColorTransform;
            gotoAndStop(8);
            break;
        case 8:
            fill_8.transform.colorTransform = myColorTransform;
            gotoAndStop(9);
            break;
        case 9:
            fill_9.transform.colorTransform = myColorTransform;
            gotoAndStop(10);
            break;
        case 10:
            fill_10.transform.colorTransform = myColorTransform;
            gotoAndStop(11);
            break;
        case 11:
            fill_11.transform.colorTransform = myColorTransform;
            gotoAndStop(12);
            break;
        case 12:
            fill_12.transform.colorTransform = myColorTransform;
            gotoAndStop(13);
            break;
        case 13:
            fill_13.transform.colorTransform = myColorTransform;
            gotoAndStop(14);
            break;
        case 14:
            fill_14.transform.colorTransform = myColorTransform;
            gotoAndStop(15);
            break;
        case 15:
            fill_151.transform.colorTransform = myColorTransform;
            gotoAndStop(16);
            break;
        case 16:
            gotoAndStop(17);
            break;
    }
});

btn_next_arrow.addEventListener(MouseEvent.MOUSE_OVER, function hovering(e:MouseEvent):void {
    trans.color = uint(0x606266);
    next_arrow.transform.colorTransform = trans;
});

btn_back_arrow.addEventListener(MouseEvent.MOUSE_OVER, function hovering1(e:MouseEvent):void {
    trans1.color = uint(0x606266);
    back_arrow.transform.colorTransform = trans1;
});

btn_next_arrow.addEventListener (MouseEvent.MOUSE_OUT, function hideShadow(event:MouseEvent):void {
    trans.color = uint(0x999999);
    next_arrow.transform.colorTransform = trans;
});

btn_back_arrow.addEventListener (MouseEvent.MOUSE_OUT, function hideShadow1(event:MouseEvent):void {
    trans1.color = uint(0x999999);
    back_arrow.transform.colorTransform = trans1;
});

btn_back_arrow.addEventListener(MouseEvent.CLICK, function goPrevLectFrame(e:MouseEvent):void {
        switch(currentFrame){
        case 2:
            gotoAndStop(1);
            break;
        case 3:
            gotoAndStop(2);
            break;
        case 4:
            gotoAndStop(3);
            break;
        case 5:
            gotoAndStop(4);
            break;
        case 6:
            gotoAndStop(5);
            break;
        case 7:
            gotoAndStop(6);
            break;
        case 8:
            gotoAndStop(7);
            break;
        case 9:
            gotoAndStop(8);
            break;
        case 10:
            gotoAndStop(9);
            break;
        case 11:
            gotoAndStop(10);
            break;
        case 12:
            gotoAndStop(11);
            break;
        case 13:
            gotoAndStop(12);
            break;
        case 14:
            gotoAndStop(13);
            break;
        case 15:
            gotoAndStop(14);
            break;
        case 16:
            gotoAndStop(15);
            break;
        }
});

btn_main_menu.addEventListener(MouseEvent.CLICK, function goPrevLectFrame1(e:MouseEvent):void {
    gotoAndStop(17);
});

问题是当我到达最后一帧并单击下一步按钮时,它显示:

TypeError: Error #1009: ... "null". at Function/()[RECOVER_shitty_fla.MainTimeline::frame1:114]

这是导致函数出现的问题:

btn_next_arrow.addEventListener (MouseEvent.MOUSE_OUT, function hideShadow(event:MouseEvent):void {
    trans.color = uint(0x999999);
    next_arrow.transform.colorTransform = trans; // LINE 114
});

我在这里真的很挣扎,非常感谢任何帮助,在此先感谢。

您需要在进入最后一帧之前移除事件侦听器。您的程序仍在侦听该帧上不存在的对象的 MouseEvents。

另外,我听从了@BadFeelingAboutThis 的建议。 内联函数是不好的做法,通常应该避免。

此代码还有其他问题(主要是小问题)。我已经从 FLA 文档中调整了您的代码以使程序运行。 查看以下更改。


第 1-16 帧

stop();

import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.StageScaleMode; 
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.geom.ColorTransform;

/** initializtios **/
var trans:ColorTransform = next_arrow.transform.colorTransform;
var p:int = 1;
var myColorTransform = new ColorTransform();
myColorTransform.color = 0x42f498;
var trans1:ColorTransform = back_arrow.transform.colorTransform;

/** actual code **/
btn_next_arrow.addEventListener(MouseEvent.CLICK, goNextLectFrame);
function goNextLectFrame(e:MouseEvent):void {
    if (p==1) {

        fill_1.transform.colorTransform = myColorTransform;
        fill_22.alpha = 0.00001;
        fill_3.alpha = 0.00001;
        fill_33.alpha = 0.00001;
        fill_5.alpha = 0.00001;
        fill_6.alpha = 0.00001;
        fill_7.alpha = 0.00001;
        fill_8.alpha = 0.00001;
        fill_9.alpha = 0.00001;
        fill_10.alpha = 0.00001;
        fill_11.alpha = 0.00001;
        fill_12.alpha = 0.00001;
        fill_13.alpha = 0.00001;
        fill_14.alpha = 0.00001;
        fill_151.alpha = 0.00001;
        ++p;
    }
    switch (currentFrame) {
        case 1:
            gotoAndStop(2);
            break;
        case 2:
            fill_22.transform.colorTransform = myColorTransform;
            gotoAndStop(3);
            break;
        case 3:
            fill_3.transform.colorTransform = myColorTransform;
            gotoAndStop(4);
            break;
        case 4:
            fill_33.transform.colorTransform = myColorTransform;
            gotoAndStop(5);
            break;
        case 5:
            fill_5.transform.colorTransform = myColorTransform;
            gotoAndStop(6);
            break;
        case 6:
            fill_6.transform.colorTransform = myColorTransform;
            gotoAndStop(7);
            break;
        case 7:
            fill_7.transform.colorTransform = myColorTransform;
            gotoAndStop(8);
            break;
        case 8:
            fill_8.transform.colorTransform = myColorTransform;
            gotoAndStop(9);
            break;
        case 9:
            fill_9.transform.colorTransform = myColorTransform;
            gotoAndStop(10);
            break;
        case 10:
            fill_10.transform.colorTransform = myColorTransform;
            gotoAndStop(11);
            break;
        case 11:
            fill_11.transform.colorTransform = myColorTransform;
            gotoAndStop(12);
            break;
        case 12:
            fill_12.transform.colorTransform = myColorTransform;
            gotoAndStop(13);
            break;
        case 13:
            fill_13.transform.colorTransform = myColorTransform;
            gotoAndStop(14);
            break;
        case 14:
            fill_14.transform.colorTransform = myColorTransform;
            gotoAndStop(15);
            break;
        case 15:
            fill_151.transform.colorTransform = myColorTransform;
            btn_next_arrow.removeEventListener(MouseEvent.MOUSE_OVER, hovering);
            btn_next_arrow.removeEventListener(MouseEvent.MOUSE_OUT, hideShadow);
            btn_back_arrow.removeEventListener(MouseEvent.MOUSE_OVER, hovering1);
            btn_back_arrow.removeEventListener(MouseEvent.MOUSE_OUT, hideShadow1);
            gotoAndStop(16);
            break;
        case 16:
            gotoAndStop(17);
            break;
    }
}

btn_next_arrow.addEventListener(MouseEvent.MOUSE_OVER, hovering);
function hovering(e:MouseEvent):void {
    trans.color = uint(0x606266);
    next_arrow.transform.colorTransform = trans;
}

btn_back_arrow.addEventListener(MouseEvent.MOUSE_OVER, hovering1);
function hovering1(e:MouseEvent):void {
    trans1.color = uint(0x606266);
    back_arrow.transform.colorTransform = trans1;
}

btn_next_arrow.addEventListener (MouseEvent.MOUSE_OUT, hideShadow);
function hideShadow(event:MouseEvent):void {
    trans.color = uint(0x999999);
    next_arrow.transform.colorTransform = trans;
}

btn_back_arrow.addEventListener (MouseEvent.MOUSE_OUT, hideShadow1);
function hideShadow1(event:MouseEvent):void {
    trans1.color = uint(0x999999);
    back_arrow.transform.colorTransform = trans1;
}

btn_back_arrow.addEventListener(MouseEvent.CLICK, goPrevLectFrame);
function goPrevLectFrame(e:MouseEvent):void {
        switch(currentFrame){
        case 2:
            gotoAndStop(1);
            break;
        case 3:
            gotoAndStop(2);
            break;
        case 4:
            gotoAndStop(3);
            break;
        case 5:
            gotoAndStop(4);
            break;
        case 6:
            gotoAndStop(5);
            break;
        case 7:
            gotoAndStop(6);
            break;
        case 8:
            gotoAndStop(7);
            break;
        case 9:
            gotoAndStop(8);
            break;
        case 10:
            gotoAndStop(9);
            break;
        case 11:
            gotoAndStop(10);
            break;
        case 12:
            gotoAndStop(11);
            break;
        case 13:
            gotoAndStop(12);
            break;
        case 14:
            gotoAndStop(13);
            break;
        case 15:
            gotoAndStop(14);
            break;
        case 16:
            gotoAndStop(15);
            break;
        }
}

btn_main_menu.addEventListener(MouseEvent.CLICK, goPrevLectFrame1);
function goPrevLectFrame1(e:MouseEvent):void {
    gotoAndStop(17);
}

第 17 帧

stop();
import flash.events.MouseEvent;

btn_goto_lect1.alpha = 0.00001;
btn_goto_pract.alpha = 0.00001;

btn_goto_lect1.addEventListener (MouseEvent.MOUSE_OVER, showShadow);
function showShadow(event:MouseEvent):void {
    btn_goto_lect1.alpha = 1;
}

btn_goto_lect1.addEventListener (MouseEvent.MOUSE_OUT, hideShadow_);
function hideShadow_(event:MouseEvent):void {
    btn_goto_lect1.alpha = 0.00001;
}

btn_goto_pract.addEventListener (MouseEvent.MOUSE_OVER, showShadow1);
function showShadow1(event:MouseEvent):void {
    btn_goto_pract.alpha = 1;
}

btn_goto_pract.addEventListener (MouseEvent.MOUSE_OUT, hideShadow2);
function hideShadow2(event:MouseEvent):void {
    btn_goto_pract.alpha = 0.00001;
}

btn_goto_lect1.addEventListener (MouseEvent.CLICK, showShadow3);

function showShadow3(event:MouseEvent):void {
    btn_goto_lect1.removeEventListener (MouseEvent.MOUSE_OVER, showShadow);
    btn_goto_lect1.removeEventListener (MouseEvent.MOUSE_OUT, hideShadow_);
    btn_goto_pract.removeEventListener (MouseEvent.MOUSE_OVER, showShadow1);
    btn_goto_pract.removeEventListener (MouseEvent.MOUSE_OUT, hideShadow2);
    gotoAndStop(1);
}