0

下面是我的按钮代码,我面临的问题是,一旦单击按钮,单击下一个按钮后将无法再次工作。我想启用上一个单击的按钮。我希望专家可以在这里帮助我。

pages.gotoAndStop("home");

// list of button instance names

var buttonsss:Array = [home, menudown.about, menudown.portfolio, menudown.clients, menudown.pricing, menudown.contact];


for each ( var mc:MovieClip in buttonsss)
{
mc.buttonMode = true;
mc.mouseChildren = false;
mc.addEventListener(MouseEvent.MOUSE_UP, onClick, false, 0, true);
mc.addEventListener(MouseEvent.ROLL_OVER, rolloverEffect, false, 0, true);
mc.addEventListener(MouseEvent.ROLL_OUT, rolloutEffect, false, 0, true);
    }

function onClick(e:MouseEvent):void
{

pages.gotoAndStop(e.target.name);
TweenLite.to(e.currentTarget,2,{tint:0xFF0000, ease:Strong.easeOut});
var myTween:Tween = new Tween(pages, "alpha", Strong.easeOut, 0, 1, 2, true);       
e.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, rolloutEffect);//disable the roll out effect
e.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, onClick);//disable the roll out effect
e.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, rolloverEffect);//disable the roll out effect

}

function rolloverEffect(e:MouseEvent):void{

TweenLite.to(e.currentTarget,2,{tint:0x000000, ease:Strong.easeOut});

}
function rolloutEffect(e:MouseEvent):void{

//should change tint to null just when its enabled, but its changing always (enabled or disabled)
TweenLite.to(e.currentTarget,2,{tint:null , ease:Strong.easeOut});

}
4

1 回答 1

0

创建一个名为focusedButton. 然后,在您的 onClick 函数中执行以下操作:

if ( focusedButton !== null ) {             
    // all the code to re-enable the previous button
    // ie add the listeners and tween alpha             
}

// be sure to store a reference to the new focused button:
focusedButton = e.currentTarget;

然后继续使用禁用新按钮的代码....

编辑 - 我看到您的评论要求更多代码。我很想让你自己弄清楚,因为我认为我已经给了你需要的一切,但由于我不知道你的经验是什么,所以我会带你走得更远一些。我希望这有帮助:

// put this at the top of your file:
var focusedButton:MovieClip = null;

// an updated onClick function ( untested )
function onClick(e:MouseEvent):void
{   
    if ( focusedButton !== null ) {             
        // just guessing your unfocus tint:
        TweenLite.to(focusedButton, 2, { tint:0xFFFFFF, ease:Strong.easeOut, onComplete:function():void {
            // remove tint here
        }});
        focusedButton.addEventListener(MouseEvent.ROLL_OUT, rolloutEffect);//enable the roll out effect
        focusedButton.addEventListener(MouseEvent.MOUSE_UP, onClick);//enable the roll out effect
        focusedButton.addEventListener(MouseEvent.ROLL_OVER, rolloverEffect);//enable the roll out effect         
    }

    // keep reference to the new button
    focusedButton = MovieClip(e.currentTarget);

    // now disable the new button etc:
    pages.gotoAndStop(e.target.name);
    TweenLite.to(e.currentTarget,2,{tint:0xFF0000, ease:Strong.easeOut});
    var myTween:Tween = new Tween(pages, "alpha", Strong.easeOut, 0, 1, 2, true);       
    e.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, rolloutEffect);//disable the roll out effect
    e.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, onClick);//disable the roll out effect
    e.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, rolloverEffect);//disable the roll out effect
}
于 2013-09-30T21:38:19.603 回答