0

在单击按钮本身以显示其下方分层的图像后,我试图使按钮消失。为了做到这一点,它可以产生任何效果,我只需要它变得透明或离开屏幕。帮助?

4

1 回答 1

0

如果您有一个名为“myButton”的按钮:

//listen for mouse clicks
myButton.addEventListener(MouseEvent.CLICK, mouseHandler);

//handle mouse clicks
function mouseHandler(event:MouseEvent):void
{
    //stop listening for clicks
    myButton.removeEventListener(MouseEvent.CLICK, mouseHandler);
    //make button invisible
    myButton.visible = false;
}

这将使按钮在单击时立即消失。如果要应用淡入淡出效果...

myButton.addEventListener(MouseEvent.CLICK, mouseHandler);

function mouseHandler(event:MouseEvent):void
{
    myButton.removeEventListener(MouseEvent.CLICK, mouseHandler);
    addEventListener(Event.ENTER_FRAME, fadeOut);
}

function fadeOut(event:Event):void
{
    var a:Number = myButton.alpha-0.05;
    if (a<=0)
    {
        a = 0;
        removeEventListener(Event.ENTER_FRAME, fadeOut);
    }
    myButton.alpha = a;
}
于 2013-04-15T17:49:14.003 回答