下面是我的按钮代码我面临的问题是,一旦点击按钮,点击下一个按钮后它就不会再次工作了。我想启用之前点击的按钮。我希望专家能在这里帮助我。
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});
}
答案 0 :(得分: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
}