0

我可以知道为什么我需要在函数 returnToInput 中再次添加“ComputeBtn.addEventListener(MouseEvent.CLICK,computeLoan)”,否则第 1 帧的按钮 ComputeBtn 将不再起作用。我没有删除监听器。只需转到第二帧显示结果并返回第一帧输入数据。

package {
    import flash.display.*;
    import flash.events.*;

    //THE CLASS DEFINITION
    public class carApp extends MovieClip {
        function carApp() {
            gotoAndStop(1);
            ComputeBtn.addEventListener(MouseEvent.CLICK,computeLoan);
        }


        function computeLoan(event:MouseEvent) {
                              gotoAndStop(2);
                              trace("Show result");
            StartAgainBtn.addEventListener(MouseEvent.CLICK,returnToInput);
        }


        function returnToInput(event:MouseEvent) {
            gotoAndStop(1);
            ComputeBtn.addEventListener(MouseEvent.CLICK,computeLoan);
        }

    }
}
4

1 回答 1

1

在您的文档类中,构造函数只运行一次,因此它只添加该侦听器一次。移动到第二帧将其删除。

在您的代码中,每次移动到第二帧时,您都在为“StartAgainBtn”设置侦听器,但如果您没有为“ComputeBtn”设置额外的侦听器,它将无法工作,因为每次移动到不同的帧时你正在失去听众。

如果您在时间轴的第一帧而不是文档类上具有相同的代码,那么它将按照您的预期工作,为“ComputeBtn”添加一次侦听器。这是因为当您返回时,第一帧上的所有代码都会重新运行。

于 2012-08-22T05:22:52.600 回答