0

我正在努力弄清楚如何为按钮/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);
4

1 回答 1

0

首先必须重新创建一个有 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

于 2013-03-09T23:18:05.380 回答