按钮不按预期运行

时间:2013-03-26 17:25:58

标签: actionscript-3 flash-cs5

我想知道是否有人可以阐明我的代码?它似乎没有任何错误地正常工作,但某些按钮不起作用。 (即进入投资菜单,然后输入&#34;查看投资组合&#34;,&#34;投资&#34;&#34;&#34;确定&#34;按钮无法正常工作。)< / p>

这是整个代码。

import flash.events.MouseEvent;
bg.stop();//Buttons
bg.ok.addEventListener(MouseEvent.CLICK, menu);
function menu(m:MouseEvent):void
{
    trace(m.target.name);
    trace(bg.currentFrame);
    if (bg.currentFrame == 1)
    {
        bg.ok.removeEventListener(MouseEvent.CLICK, menu);
        bg.gotoAndStop(2);
        bg.menubtn.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame == 2 || bg.currentFrame == 4 && m.target.name == "Menubtn4" || bg.currentFrame == 5 && m.target.name == "Menubtn5" || bg.currentFrame == 6 && m.target.name == "backtomain" || bg.currentFrame == 7 && m.target.name == "Menubtn7" || bg.currentFrame == 9 && m.target.name == "Menubtn9" || bg.currentFrame == 13 && m.target.name == "Menubtn13"  || bg.currentFrame == 20 && m.target.name == "backtomenu20" || bg.currentFrame == 24 && m.target.name == "Menubtn24" || bg.currentFrame == 27 && m.target.name == "backtomenu27" )
    {
        if (m.target.name == "menubtn")
        {
            bg.menubtn.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "Menubtn4")
        {
            bg.Menubtn4.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "Menubtn5")
        {
            bg.Menubtn5.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "backtomain")
        {
            bg.backtomain.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "Menubtn7")
        {
            bg.Menubtn7.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "Menubtn9")
        {
            bg.Menubtn9.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "Menubtn13")
        {
            bg.Menubtn13.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "backtomenu20")
        {
            bg.backtomenu20.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "Menubtn24")
        {
            bg.Menubtn24.removeEventListener(MouseEvent.CLICK, menu);
        }
        else if (m.target.name == "backtomenu27")
        {
            bg.backtomenu27.removeEventListener(MouseEvent.CLICK, menu);
        }
        bg.gotoAndStop(3);
        bg.Balinq.addEventListener(MouseEvent.CLICK, menu);
        bg.Transinq.addEventListener(MouseEvent.CLICK, menu);
        bg.Fintrxns.addEventListener(MouseEvent.CLICK, menu);
        bg.invest.addEventListener(MouseEvent.CLICK, menu);
        bg.others.addEventListener(MouseEvent.CLICK, menu);
        bg.passchange.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==3)
    {
        bg.Balinq.removeEventListener(MouseEvent.CLICK, menu);
        bg.Transinq.removeEventListener(MouseEvent.CLICK, menu);
        bg.Fintrxns.removeEventListener(MouseEvent.CLICK, menu);
        bg.invest.removeEventListener(MouseEvent.CLICK, menu);
        bg.others.removeEventListener(MouseEvent.CLICK, menu);
        bg.passchange.removeEventListener(MouseEvent.CLICK, menu);
        if (m.target.name == "Balinq")
        {
            bg.gotoAndStop(2);
            bg.menubtn.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "Transinq")
        {
            bg.gotoAndStop(4);
            bg.Menubtn4.addEventListener(MouseEvent.CLICK, menu);
            bg.okbtn4.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "Fintrxns")
        {
            bg.gotoAndStop(6);
            bg.backtomain.addEventListener(MouseEvent.CLICK, menu);
            bg.transown.addEventListener(MouseEvent.CLICK, menu);
            bg.transthird.addEventListener(MouseEvent.CLICK, menu);
            bg.transanyone.addEventListener(MouseEvent.CLICK, menu);
            bg.billsdeposit.addEventListener(MouseEvent.CLICK, menu);
            bg.billscredit.addEventListener(MouseEvent.CLICK, menu);
            bg.reloadphone.addEventListener(MouseEvent.CLICK, menu);
            bg.reloadwallet.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "others")
        {
            bg.gotoAndStop(20);
            bg.backtomenu20.addEventListener(MouseEvent.CLICK, menu);
            bg.checkbook.addEventListener(MouseEvent.CLICK, menu);
            bg.stoppay.addEventListener(MouseEvent.CLICK, menu);
            bg.enrollacct.addEventListener(MouseEvent.CLICK, menu);
            bg.enrollthird.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "passchange")
        {
            bg.gotoAndStop(24);
            bg.Menubtn24.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "invest")
        {
            bg.gotoAndStop(27);
            bg.backtomenu27.addEventListener(MouseEvent.CLICK, menu);
            bg.viewport.addEventListener(MouseEvent.CLICK, menu);
            bg.viewhist.addEventListener(MouseEvent.CLICK, menu);
            bg.subscribe.addEventListener(MouseEvent.CLICK, menu);
            bg.redeem.addEventListener(MouseEvent.CLICK, menu);
        }
    }
    else if (bg.currentFrame==4)
    {
        bg.Menubtn4.removeEventListener(MouseEvent.CLICK, menu);
        bg.okbtn4.removeEventListener(MouseEvent.CLICK, menu);
        bg.gotoAndStop(5);
        bg.Menubtn5.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==6)
    {
        bg.backtomain.removeEventListener(MouseEvent.CLICK, menu);
        bg.transown.removeEventListener(MouseEvent.CLICK, menu);
        bg.transthird.removeEventListener(MouseEvent.CLICK, menu);
        bg.transanyone.removeEventListener(MouseEvent.CLICK, menu);
        bg.reloadphone.removeEventListener(MouseEvent.CLICK, menu);
        if (m.target.name == "transown")
        {
            bg.gotoAndStop(7);
            bg.Menubtn7.addEventListener(MouseEvent.CLICK, menu);
            bg.okbtn7.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "transthird")
        {
            bg.gotoAndStop(9);
            bg.Menubtn9.addEventListener(MouseEvent.CLICK, menu);
            bg.okbtn9.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "transanyone")
        {
            bg.gotoAndStop(13);
            bg.Menubtn13.addEventListener(MouseEvent.CLICK, menu);
            bg.okbtn13.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "billsdeposit")
        {
            bg.gotoAndStop(15);
            bg.finbtn15.addEventListener(MouseEvent.CLICK, menu);
            bg.okbtn15.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "billscredit")
        {
            bg.gotoAndStop(28);
            bg.finbtn28.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "reloadphone")
        {
            bg.gotoAndStop(17);
            bg.finbtn17.addEventListener(MouseEvent.CLICK, menu);
            bg.okbtn17.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "reloadwallet")
        {
            bg.gotoAndStop(18);
            bg.finbtn18.addEventListener(MouseEvent.CLICK, menu);
        }
    }
    else if (bg.currentFrame==7)
    {
        bg.Menubtn7.removeEventListener(MouseEvent.CLICK, menu);
        bg.okbtn7.removeEventListener(MouseEvent.CLICK, menu);
        if (m.target.name == "okbtn7")
        {
            bg.gotoAndStop(8);
            bg.finbtn8.addEventListener(MouseEvent.CLICK, menu);
        }
        } ;/*current frame 8*/
    }
    else if (m.target.name=="finbtn8" || m.target.name=="finbtn10" || m.target.name=="finbtn11" || m.target.name=="finbtn12" || m.target.name=="finbtn14" || m.target.name=="finbtn15" || m.target.name=="finbtn16" || m.target.name=="finbtn17" || m.target.name=="finbtn18" ||m.target.name=="finbtn26" ||m.target.name=="finbtn28")
    {
        if (m.target.name == "finbtn8")
        {
            bg.finbtn8.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn10")
        {
            bg.finbtn10.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn11")
        {
            bg.finbtn11.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn12")
        {
            bg.finbtn12.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn14")
        {
            bg.finbtn14.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn15")
        {
            bg.finbtn15.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn16")
        {
            bg.finbtn16.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn17")
        {
            bg.finbtn17.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn18")
        {
            bg.finbtn18.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn26")
        {
            bg.finbtn26.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "finbtn28")
        {
            bg.finbtn28.removeEventListener(MouseEvent.CLICK, menu);
        }
        bg.gotoAndStop(6);
        bg.backtomain.addEventListener(MouseEvent.CLICK, menu);
        bg.transown.addEventListener(MouseEvent.CLICK, menu);
        bg.transthird.addEventListener(MouseEvent.CLICK, menu);
        bg.transanyone.addEventListener(MouseEvent.CLICK, menu);
        bg.billsdeposit.addEventListener(MouseEvent.CLICK, menu);
        bg.billscredit.addEventListener(MouseEvent.CLICK, menu);
        bg.reloadphone.addEventListener(MouseEvent.CLICK, menu);
        bg.reloadwallet.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==9 || m.target.name=="backbtn11")
    {
        if (bg.currentFrame == 9)
        {
            bg.Menubtn9.removeEventListener(MouseEvent.CLICK, menu);
            bg.okbtn9.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "backbtn11")
        {
            bg.finbtn11.removeEventListener(MouseEvent.CLICK, menu);
            bg.okbtn11.removeEventListener(MouseEvent.CLICK, menu);
            bg.backbtn11.removeEventListener(MouseEvent.CLICK, menu);
        }
        bg.gotoAndStop(10);
        bg.finbtn10.addEventListener(MouseEvent.CLICK, menu);
        bg.okbtn10.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==10)
    {
        bg.finbtn10.removeEventListener(MouseEvent.CLICK, menu);
        bg.okbtn10.removeEventListener(MouseEvent.CLICK, menu);
        bg.gotoAndStop(11);
        bg.finbtn11.addEventListener(MouseEvent.CLICK, menu);
        bg.okbtn11.addEventListener(MouseEvent.CLICK, menu);
        bg.backbtn11.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==11)
    {
        bg.finbtn11.removeEventListener(MouseEvent.CLICK, menu);
        bg.okbtn11.removeEventListener(MouseEvent.CLICK, menu);
        bg.backbtn11.removeEventListener(MouseEvent.CLICK, menu);
        bg.gotoAndStop(12);
        bg.finbtn12.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==13)
    {
        bg.Menubtn13.removeEventListener(MouseEvent.CLICK, menu);
        bg.okbtn13.removeEventListener(MouseEvent.CLICK, menu);
        bg.gotoAndStop(14);
        bg.finbtn14.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==15)
    {
        bg.finbtn15.removeEventListener(MouseEvent.CLICK, menu);
        bg.okbtn15.removeEventListener(MouseEvent.CLICK, menu);
        bg.gotoAndStop(16);
        bg.finbtn16.addEventListener(MouseEvent.CLICK, menu);
        bg.backbtn16.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==16)
    {
        bg.gotoAndStop(15);
        bg.finbtn15.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==17)
    {
        bg.finbtn17.removeEventListener(MouseEvent.CLICK, menu);
        bg.okbtn17.removeEventListener(MouseEvent.CLICK, menu);
        bg.gotoAndStop(26);
        bg.finbtn26.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==20)
    {
        bg.backtomenu20.removeEventListener(MouseEvent.CLICK, menu);
        bg.checkbook.removeEventListener(MouseEvent.CLICK, menu);
        bg.stoppay.removeEventListener(MouseEvent.CLICK, menu);
        bg.enrollacct.removeEventListener(MouseEvent.CLICK, menu);
        bg.enrollthird.removeEventListener(MouseEvent.CLICK, menu);
        if (m.target.name == "checkbook")
        {
            bg.gotoAndStop(21);
            bg.otherbtn21.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "stoppay")
        {
            bg.gotoAndStop(22);
            bg.otherbtn22.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "enrollacct")
        {
            bg.gotoAndStop(23);
            bg.otherbtn23.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "enrollthird")
        {
            bg.gotoAndStop(25);
            bg.otherbtn25.addEventListener(MouseEvent.CLICK, menu);
        }
    }
    else if (m.target.name=="otherbtn21" || m.target.name=="otherbtn22" || m.target.name=="otherbtn23" || m.target.name=="otherbtn25")
    {
        if (m.target.name == "otherbtn21")
        {
            bg.otherbtn21.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "otherbtn22")
        {
            bg.otherbtn22.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "otherbtn23")
        {
            bg.otherbtn23.removeEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "otherbtn25")
        {
            bg.otherbtn25.removeEventListener(MouseEvent.CLICK, menu);
        }
        bg.gotoAndStop(20);
        bg.backtomenu20.addEventListener(MouseEvent.CLICK, menu);
        bg.checkbook.addEventListener(MouseEvent.CLICK, menu);
        bg.stoppay.addEventListener(MouseEvent.CLICK, menu);
        bg.enrollacct.addEventListener(MouseEvent.CLICK, menu);
        bg.enrollthird.addEventListener(MouseEvent.CLICK, menu);
    }
    else if (bg.currentFrame==27)
    {
        bg.backtomenu27.removeEventListener(MouseEvent.CLICK, menu);
        bg.viewport.removeEventListener(MouseEvent.CLICK, menu);
        bg.viewhist.removeEventListener(MouseEvent.CLICK, menu);
        bg.subscribe.removeEventListener(MouseEvent.CLICK, menu);
        bg.redeem.removeEventListener(MouseEvent.CLICK, menu);
        if (m.target.name == "viewport")
        {
            bg.gotoAndStop(29);
            bg.backtoinvest29.addEventListener(MouseEvent.CLICK, menu);
            bg.okinvest1.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "viewhist")
        {
            bg.gotoAndStop(32);
            bg.backtoinvest32.addEventListener(MouseEvent.CLICK, menu);
            bg.donebtn32.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "subscribe")
        {
            bg.gotoAndStop(35);
            bg.backtoinvest35.addEventListener(MouseEvent.CLICK, menu);
            bg.donebtn35.addEventListener(MouseEvent.CLICK, menu);
        }
        if (m.target.name == "redeem")
        {
            bg.gotoAndStop(42);
            bg.backtoinvest42.addEventListener(MouseEvent.CLICK, menu);
            bg.okinvest4.addEventListener(MouseEvent.CLICK, menu);
        }
        else if (bg.currentFrame==29)
        {
            bg.backtoinvest29.removeEventListener(MouseEvent.CLICK, menu);
            bg.okinvest1.removeEventListener(MouseEvent.CLICK, menu);
            if (m.target.name == "okinvest1")
            {
                bg.gotoAndStop(30);
                bg.backtoinvest30.addEventListener(MouseEvent.CLICK, menu);
            }
            else if (bg.currentFrame ==30)
            {
                bg.backtoinvest30.removeEventListener(MouseEvent.CLICK, menu);
                bg.donebtn30.addEventListener(MouseEvent.CLICK, menu);
                if (m.target.name == "donebtn30")
                {
                    bg.gotoAndStop(31);
                    bg.backtoinvest31.addEventListener(MouseEvent.CLICK, menu);
                }
            }
            else if (m.target.name=="backtoinvest29" || m.target.name=="backtoinvest30" || m.target.name=="backtoinvest31" || m.target.name=="backtoinvest32" || m.target.name=="backtoinvest33" || m.target.name=="backtoinvest34" || m.target.name=="backtoinvest35" || m.target.name=="backtoinvest36" || m.target.name=="backtoinvest37" || m.target.name=="backtoinvest38" ||m.target.name=="backtoinvest39" || m.target.name=="backtoinvest41" || m.target.name=="backtoinvest42" || m.target.name=="backtoinvest43" || m.target.name=="backtoinvest44" || m.target.name=="backtoinvest45" || m.target.name=="backtoinvest46" || m.target.name=="backtoinvest47" || m.target.name=="backtoinvest48")
            {
                if (m.target.name == "backtoinvest29")
                {
                    bg.backtoinvest29.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest30")
                {
                    bg.backtoinvest30.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest31")
                {
                    bg.backtoinvest31.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest32")
                {
                    bg.backtoinvest32.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest33")
                {
                    bg.backtoinvest33.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest34")
                {
                    bg.backtoinvest34.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest35")
                {
                    bg.backtoinvest35.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest36")
                {
                    bg.backtoinvest36.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest37")
                {
                    bg.backtoinvest37.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest38")
                {
                    bg.backtoinvest38.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest39")
                {
                    bg.backtoinvest39.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest41")
                {
                    bg.backtoinvest41.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest42")
                {
                    bg.backtoinvest42.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest43")
                {
                    bg.backtoinvest43.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest44")
                {
                    bg.backtoinvest44.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest45")
                {
                    bg.backtoinvest45.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest46")
                {
                    bg.backtoinvest46.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest46")
                {
                    bg.backtoinvest46.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest47")
                {
                    bg.backtoinvest47.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "backtoinvest48")
                {
                    bg.backtoinvest48.removeEventListener(MouseEvent.CLICK, menu);
                }
                bg.gotoAndStop(27);
                bg.backtomenu27.addEventListener(MouseEvent.CLICK, menu);
                bg.viewport.addEventListener(MouseEvent.CLICK, menu);
                bg.viewhist.addEventListener(MouseEvent.CLICK, menu);
                bg.subscribe.addEventListener(MouseEvent.CLICK, menu);
                bg.redeem.addEventListener(MouseEvent.CLICK, menu);
            }
            else if (bg.currentFrame==32)
            {
                if (bg.currentFrame == 32)
                {
                    bg.backtoinvest32.removeEventListener(MouseEvent.CLICK, menu);
                    bg.donebtn32.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "donebtn32")
                {
                    bg.gotoAndStop(33);
                    bg.backtoinvest33.addEventListener(MouseEvent.CLICK, menu);
                    bg.okinvest2.addEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okinvest2")
                {
                    bg.gotoAndStop(34);
                    bg.backtoinvest33.removeEventListener(MouseEvent.CLICK, menu);
                    bg.okinvest2.removeEventListener(MouseEvent.CLICK, menu);
                    bg.backtoinvest34.addEventListener(MouseEvent.CLICK, menu);
                }
            }
            else if (bg.currentFrame==35)
            {
                bg.backtoinvest35.removeEventListener(MouseEvent.CLICK, menu);
                bg.donebtn35.removeEventListener(MouseEvent.CLICK, menu);
                if (m.target.name == "donebtn35")
                {
                    bg.gotoAndStop(36);
                    bg.backtoinvest36.addEventListener(MouseEvent.CLICK, menu);
                    bg.okinvest3.addEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okinvest3")
                {
                    bg.gotoAndStop(37);
                    bg.backtoinvest37.addEventListener(MouseEvent.CLICK, menu);
                    bg.donebtn37.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==37)
                {
                    bg.backtoinvest36.removeEventListener(MouseEvent.CLICK, menu);
                    bg.okinvest3.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "donebtn37")
                {
                    bg.gotoAndStop(38);
                    bg.backtoinvest38.addEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn38.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==38)
                {
                    bg.backtoinvest37.removeEventListener(MouseEvent.CLICK, menu);
                    bg.donebtn37.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okbtn38")
                {
                    bg.gotoAndStop(39);
                    bg.backtoinvest39.addEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn39.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==39)
                {
                    bg.backtoinvest38.removeEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn38.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okbtn39")
                {
                    bg.gotoAndStop(40);
                    bg.backtoinvest39.removeEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn39.removeEventListener(MouseEvent.CLICK, menu);
                    bg.backtoinvest39.removeEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn40.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==40)
                {
                    bg.okbtn40.removeEventListener(MouseEvent.CLICK, menu);
                    bg.backtoinvest40.addEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okbtn40")
                {
                    bg.gotoAndStop(41);
                    bg.backtoinvest41.addEventListener(MouseEvent.CLICK, menu);
                }
            }
            else if (bg.currentFrame==42)
            {
                bg.backtoinvest42.removeEventListener(MouseEvent.CLICK, menu);
                bg.okinvest4.removeEventListener(MouseEvent.CLICK, menu);
                if (m.target.name == "okinvest4")
                {
                    bg.gotoAndStop(42);
                    bg.backtoinvest43.addEventListener(MouseEvent.CLICK, menu);
                    bg.donebtn43.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==43)
                {
                    bg.backtoinvest43.removeEventListener(MouseEvent.CLICK, menu);
                    bg.donebtn43.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "donebtn43")
                {
                    bg.gotoAndStop(44);
                    bg.backtoinvest44.addEventListener(MouseEvent.CLICK, menu);
                    bg.donebtn44.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==44)
                {
                    bg.backtoinvest44.removeEventListener(MouseEvent.CLICK, menu);
                    bg.donebtn44.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "donebtn44")
                {
                    bg.gotoAndStop(45);
                    bg.backtoinvest45.addEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn45.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==45)
                {
                    bg.backtoinvest45.removeEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn45.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okbtn45")
                {
                    bg.gotoAndStop(46);
                    bg.backtoinvest46.addEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn46.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==46)
                {
                    bg.backtoinvest46.removeEventListener(MouseEvent.CLICK, menu);
                    bg.okbtn46.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okbtn46")
                {
                    bg.gotoAndStop(47);
                    bg.okbtn47.addEventListener(MouseEvent.CLICK, menu);
                }
                else if (bg.currentFrame==47)
                {
                    bg.okbtn47.removeEventListener(MouseEvent.CLICK, menu);
                }
                if (m.target.name == "okbtn47")
                {
                    bg.gotoAndStop(48);
                    bg.backtoinvest48.addEventListener(MouseEvent.CLICK, menu);
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

虽然提供“所有代码”很有用,但在这种情况下,您正在混淆您正在处理的核心问题。在其中没有任何地方可以找到“查看投资组合”或“投资”字样,并且对于所有其他按钮注册,它需要逐行阅读以查看您是否拼错了按钮。

此外,由于这些界面元素似乎没有动态创建(而是使用Flash IDE,因此存在于看不见的库中),因此我们无法确定正确的变量名称应该是什么。

简明扼要。提供尽可能少的代码来重现问题。

<强>简化即可。每当你看到重复的代码模式时,它可能意味着你可以通过函数或循环来减少。

所有这些按钮都是注册或取消注册'(MouseEvent.CLICK,menu)'。你可以通过循环更快地完成这项工作,例如......

var buttons:Array = [
    bg.ok,
    bg.menubtn,
    bg.Balinq,
    bg.Transinq,
    bg.Fintrxns,
    bg.invest,
    bg.others,
    bg.passchange
]

for (var btn in buttons) {
    btn.addEventListener(MouseEvent.CLICK, menu);
}

现在当你需要对所有这些按钮做一些事情时,你只需要看一个地方。


单击按钮时,您将测试对象的名称并取消注册。您可以避免此测试,只需取消注册目标即可。因此而不是:

if (m.target.name == "menubtn") {
    bg.menubtn.removeEventListener(MouseEvent.CLICK, menu);
}

只是做:

m.target.removeEventListener(MouseEvent.CLICK, menu);

简化代码的另一种方法是使用switch operator。像这样的方法......

if (m.target.name == "viewport") {
    // do a
}
if (m.target.name == "viewhist") {
    // do b
}
if (m.target.name == "subscribe") {
    // do c
}

可以成为......

switch (m.target.name) {
    case "viewport": // do a
        break;
    case "viewhist": // do b
        break;
    case "subscribe": // do c
        break;
}

当你知道你总是在对同一个变量进行测试时,这很方便。


最后,reuseable code意味着轻量级代码易于维护,减少了工作量,并使文档更具可读性。通过你在这里做的事情,我相当有信心你可以把它从650行下载到大约50行代码。