【问题标题】:(AS3) add active state button code to the following code(AS3) 在下面的代码中添加活动状态按钮代码
【发布时间】:2013-03-09 22:56:49
【问题描述】:

我正在努力弄清楚如何为按钮/s 编写一个活动状态(显示当前页面)这是我目前所拥有的:

stop();

  function handleClick (p_event:MouseEvent) :void
  {
    if(p_event.target == logo_btn)
    {
        gotoAndStop(1, "Home");
    }
    if(p_event.target == home_btn)
    {
        gotoAndStop(1, "Home");
    }
    if(p_event.target == portfolio_btn)
    {
        gotoAndStop(1, "Portfolio");
    }
    if(p_event.target == press_btn)
    {
        gotoAndStop(1, "Press");
    }
    if(p_event.target == links_btn)
    {
        gotoAndStop(1, "Links");
    }
    if(p_event.target == contact_btn)
    {
        gotoAndStop(1, "Contact");
    }
  }

  stop();

  home_btn.addEventListener(MouseEvent.CLICK, handleClick);
  portfolio_btn.addEventListener(MouseEvent.CLICK, handleClick);
  press_btn.addEventListener(MouseEvent.CLICK, handleClick);
  links_btn.addEventListener(MouseEvent.CLICK, handleClick);
  contact_btn.addEventListener(MouseEvent.CLICK, handleClick);

【问题讨论】:

    标签: actionscript-3 flash button


    【解决方案1】:

    首先必须重新创建一个有 2 帧的 Button,1 帧是非活动的 ui 2 帧是活动的 ui。他们还有 1 帧 stop(); 脚本。在主时间轴中声明临时变量,并将当前选定的按钮存储在 MouseClick 处理程序中。下一个 Active / InActive 任​​务执行。

    var selectedButton:MovieClip;
    function handleClick(p_event:MouseEvent):void
    {
        var clickedClip:MovieClip = p_event.target as MovieClip;
    
        if (clickedClip == logo_btn)
        {
            if (selectedButton)
                selectedButton.gotoAndStop(1);
            selectedButton = logo_btn;
            selectedButton.gotoAndStop(2);
            gotoAndStop(1, "Home");
        }
        else if (clickedClip == home_btn)
        {
            if (selectedButton)
                selectedButton.gotoAndStop(1);
            selectedButton = home_btn;
            selectedButton.gotoAndStop(2);
            gotoAndStop(1, "Home");
        }
        else if (clickedClip == portfolio_btn)
        {
            if (selectedButton)
                selectedButton.gotoAndStop(1);
            selectedButton = portfolio_btn;
            selectedButton.gotoAndStop(2);
            gotoAndStop(1, "Portfolio");
        }
        else if (clickedClip == press_btn)
        {
            if (selectedButton)
                selectedButton.gotoAndStop(1);
            selectedButton = press_btn;
            selectedButton.gotoAndStop(2);
            gotoAndStop(1, "Press");
        }
        else if (clickedClip == links_btn)
        {
            if (selectedButton)
                selectedButton.gotoAndStop(1);
            selectedButton = links_btn;
            selectedButton.gotoAndStop(2);
            gotoAndStop(1, "Links");
        }
        else if (clickedClip == contact_btn)
        {
            if (selectedButton)
                selectedButton.gotoAndStop(1);
            selectedButton = contact_btn;
            selectedButton.gotoAndStop(2);
            gotoAndStop(1, "Contact");
        }
    }
    

    这是我的示例代码:ActiveButtonTest

    【讨论】:

    • 我明白你在说什么,如果我从一开始就创建了一个 mc,它会起作用,但我必须先创建一个按钮,然后将按下状态的按钮转换为影片剪辑。它会那样工作吗? (我的过度状态也是一个 mc,因为我正在对其应用过滤器。
    • 你的想法和上面的过程一样吗。没有困难。 gotoAndStop() 替换为您的代码。考虑以下问题。 gotoAndStop(1)=> 删除过滤器,gotoAndStop(2) => 设置过滤器
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多