(AS3)将活动状态按钮代码添加到以下代码中

时间:2013-03-09 22:56:50

标签: actionscript-3 flash button

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

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

1 个答案:

答案 0 :(得分:0)

首先必须重新创建一个具有2帧的按钮,1帧处于非活动状态ui 2帧是活动的ui。他们还有1帧stop();脚本。在主时间轴中声明临时变量,并在MouseClick处理程序中存储当前选定的Button。下一个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