Flex中的简单效果

时间:2020-03-05 18:47:11  来源:igfitidea点击:

我想在Flex应用程序中显示一些隐藏的文本,并使其在几秒钟内消失...

我研究了Flex中的"延迟"和"暂停"效果,但是还没有看到如何实现这种实际上很简单的效果的示例...

现在有人怎么做或者拥有良好的资源吗?

谢谢。

解决方案

回答

如果我理解正确,我们想让文本在显示后几秒钟自动淡出吗?

我可能会做这样的事情:(还没有测试代码,所以可能有错别字。)

<mx:Script>
    import flash.utils.*;

    var fadeTimer:Timer = new Timer(2000); // 2 seconds
    fadeTimer.addEventListener("timer", fadeTimerTickHandler);

    // Call this to show the hidden text.
    function showTheText():void{
        theTextField.visible = true;
        fadeTimer.start();
        }

    // This gets called every time the timer "ticks" (2 seconds)
    function fadeTimerTickHandler(eventArgs:TimerEvent){
       fadeTimer.stop();
       fadeTimer.reset();
       theTextField.visible = false;
       }
</mx:Script>

<mx:Fade id="hideEffectFade" alphaFrom="1.0" alphaTo="0.0" duration="900"/>

<mx:Text id="theTextField" text="The Text" hideEffect="{hideEffectFade}"/>

另外,我们需要确保嵌入字体,否则效果对文本不起作用。有关更多信息,请参见Simeon的帖子。