Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 等待Flex效果完成_Apache Flex_Actionscript 3 - Fatal编程技术网

Apache flex 等待Flex效果完成

Apache flex 等待Flex效果完成,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我是Flex新手,负责增强现有应用程序。其中一个增强功能是获取当前显示时间的字段,以便在显示时间和日期之间平滑地来回衰减 我知道正确的方法是将字体文件嵌入到应用程序中,这样我就可以直接淡入淡出标签。如果可以的话,我会尽量避免这种情况,因为我更愿意让我的改变尽可能不引人注目 我想出了一个合理的解决办法:创建一个“隐私屏幕”,恰好是时钟背景的准确大小、形状和颜色;将其alpha初始化为0;然后在更改时间/日期时,淡入隐私屏幕,进行更改,然后再次淡出屏幕 代码如下所示: var target

我是Flex新手,负责增强现有应用程序。其中一个增强功能是获取当前显示时间的字段,以便在显示时间和日期之间平滑地来回衰减

我知道正确的方法是将字体文件嵌入到应用程序中,这样我就可以直接淡入淡出标签。如果可以的话,我会尽量避免这种情况,因为我更愿意让我的改变尽可能不引人注目

我想出了一个合理的解决办法:创建一个“隐私屏幕”,恰好是时钟背景的准确大小、形状和颜色;将其alpha初始化为0;然后在更改时间/日期时,淡入隐私屏幕,进行更改,然后再次淡出屏幕

代码如下所示:


    var targets:Array = new Array();
    targets.push(this.privacyScreen);
    this.effectFadeIn.play(targets);
    this.mylabel.text = "I am a date and/or time";
    this.effectFadeOut.play(targets);

<mx:Label text="" id="mylabel" width="100%" height="100%" x="0" y="0" color="0xff0000"/>
<mx:Canvas id="privacyScreen" width="100%" height="100%" x="0" y="0" alpha="1" backgroundColor="{myConfiguration.backgroundColor}"/>
<mx:Fade id="effectFadeIn" alphaFrom="0.0" alphaTo="1.0" duration="250"/>
<mx:Fade id="effectFadeOut" alphaFrom="1.0" alphaTo="0.0" duration="250"/>
。。。关键组件如下所示:


    var targets:Array = new Array();
    targets.push(this.privacyScreen);
    this.effectFadeIn.play(targets);
    this.mylabel.text = "I am a date and/or time";
    this.effectFadeOut.play(targets);

<mx:Label text="" id="mylabel" width="100%" height="100%" x="0" y="0" color="0xff0000"/>
<mx:Canvas id="privacyScreen" width="100%" height="100%" x="0" y="0" alpha="1" backgroundColor="{myConfiguration.backgroundColor}"/>
<mx:Fade id="effectFadeIn" alphaFrom="0.0" alphaTo="1.0" duration="250"/>
<mx:Fade id="effectFadeOut" alphaFrom="1.0" alphaTo="0.0" duration="250"/>

我相信经验丰富的Flex设计师已经知道,这段代码是由delicious fresh StreedFAIL编写的。执行将等待淡入效果完成的基本假设是错误的,淡出效果显然在淡入过程中被忽略

所以我想我有两个相关的问题:

  • 是否有可能在等待效果运行完成时暂停执行
  • 这种方法是可行的,还是仅仅是自上而下做错事的臭味
  • 我提前感谢任何人提供的任何见解

    (我事先承认,我越是想通过实践来了解这一点,我就越意识到我需要利用一些在线资源。)

    您的代码在标签消失时执行。this.effectFadeIn.play()不会等待它完成。我会在以后需要调用的代码行中添加一个setTimeout调用,或者更好的是,将它们放在另一个函数中。然后,在一定间隔后再次调用该函数

    import flash.utils.*;
    
    private function FadeIn () : void {
        var targets:Array = new Array();
        targets.push(this.privacyScreen);
        this.effectFadeIn.play(targets);
        this.mylabel.text = "I am a date and/or time";
        setTimeout (function (): void {FadeOut (targets);}, effectFadeIn.duration); // Function and duration
    }
    private function FadeOut (targets : Array) : void {
        this.effectFadeOut.play(targets);
        setTimeout (FadeIn (), this.effectFadeOut.duration;
    }
    

    我很确定这应该行得通…

    我刚刚对你的代码做了一些修改,这就是你想要的吗

    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="absolute"
        creationComplete="onComplete();">
    
        <mx:Script>
            <![CDATA[
                private var targets:Array = new Array();
                private function onComplete():void {
                    targets.push(canv);
                    effectFadeOut.play(targets);
                }
                private function onFadeInEnd():void {
                    effectFadeOut.play(targets);
                }
                private function onFadeOutEnd():void {
                    effectFadeIn.play(targets);
                }
            ]]>
        </mx:Script>
    
        <mx:Label text="{(new Date()).toString()}" id="lbl" x="0" y="0" color="0xff0000"/>
        <mx:Canvas id="canv" width="100%" height="{lbl.height+5}" x="0" y="0" backgroundColor="#000000"/>
    
        <mx:Fade id="effectFadeIn" alphaFrom="0.0" alphaTo="1.0" duration="250"
            effectEnd="onFadeInEnd();" />
        <mx:Fade id="effectFadeOut" alphaFrom="1.0" alphaTo="0.0" duration="250"
            effectEnd="onFadeOutEnd();" />
    
    </mx:WindowedApplication>
    
    
    

    希望有帮助:)

    啊哈!“effectEnd”参数正是实现这一点所需的机制,此示例代码非常好地演示了这一概念。谢谢你。你的帖子让我免于一些真正的悲痛。谢谢它几乎起作用了。它需要一些调整来完成我的拍摄目标,因为我想在隐私屏幕消失后更改文本,但只需将文本更改移动到淡出功能中即可。我接受了radekg的答案,而不是这一个,因为我觉得它更优雅,而且根据我在其他地方读到的内容,它看起来像是Adobe试图反对setTimeout函数。但是,无论如何+1表示帮助;这是功能完善的解决方案的核心。:-)从来没有在Flex中使用过特效,这是我脑子里想不到的:-)我也是Javascript世界的人,在JS中就是这样做的。