0
votes

May I know why I need to add "ComputeBtn.addEventListener(MouseEvent.CLICK,computeLoan)" at the function returnToInput again, else the button ComputeBtn at frame 1 will not work again. I haven't remove the listener. Just goto the second frame to show the result and go back to first frame for enter the data.

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);
        }

    }
}
1

1 Answers

1
votes

In your document class, the constructor is only run once so it only adds that listener one time. Moving to frame two removes it.

In your code each time you move to frame two you're setting the listener for the 'StartAgainBtn' but if you didn't have the additional listener for the 'ComputeBtn' it won't work since each time you move to a different frame you're losing the listeners.

If you had the same code on frame one of the timeline instead of a document class it would work as you expect with the listener added once for the 'ComputeBtn'. This is because all the code on frame one would re-run again when you returned.