Actionscript 3 失去焦点时,在动画实例的每次迭代中重复不触发的效果
我不确定这个标题是否具有足够的描述性,但这里是基本问题。我有一个spark.effects.Animate实例在Actionscript 3 失去焦点时,在动画实例的每次迭代中重复不触发的效果,actionscript-3,flash,google-chrome,flex4,Actionscript 3,Flash,Google Chrome,Flex4,我不确定这个标题是否具有足够的描述性,但这里是基本问题。我有一个spark.effects.Animate实例在EFFECT\u REPEAT事件中与侦听器重复n次。在该事件的侦听器中,我正在递增一个变量。逻辑将规定,如果变量从0开始,并且动画播放时repeatCount为3,则完成时变量将为2。这很好,直到我聚焦到另一个选项卡。执行此操作时,有时不会触发/处理重复事件(或者动画实际上没有执行动画),并且完成时我的计数不正确 这是一个基于Flex 4.5构建的功能完整的示例。要复制,只需单击GO
EFFECT\u REPEAT
事件中与侦听器重复n次。在该事件的侦听器中,我正在递增一个变量。逻辑将规定,如果变量从0开始,并且动画播放时repeatCount
为3,则完成时变量将为2。这很好,直到我聚焦到另一个选项卡。执行此操作时,有时不会触发/处理重复事件(或者动画实际上没有执行动画),并且完成时我的计数不正确
这是一个基于Flex 4.5构建的功能完整的示例。要复制,只需单击GO按钮并在选项卡上保持焦点。然后再次单击它,切换选项卡并切换回。计数不匹配
如何修复此问题,以便一致地调用重复事件
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="600" height="400" applicationComplete="application1_applicationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Image;
import mx.events.EffectEvent;
import mx.events.FlexEvent;
import spark.effects.Animate;
import spark.effects.animation.MotionPath;
import spark.effects.animation.SimpleMotionPath;
private var animate:Animate;
private var someCounter:int = 0;
protected function application1_applicationCompleteHandler(event:FlexEvent):void
{
// Create the graphic
var img:Image = new Image();
img.source = "http://www.google.com/intl/en_com/images/srpr/logo3w.png";
// Add the graphic
addElement( img );
// Create the motion path
var smp:SimpleMotionPath = new SimpleMotionPath();
smp.property = "x";
smp.valueFrom = 0;
smp.valueTo = this.width - 275;
// Add the motion path to a Vector
var paths:Vector.<MotionPath> = new Vector.<MotionPath>();
paths.push( smp );
// Create the animation
animate = new Animate();
animate.easer = null;
animate.target = img;
animate.duration = 150;
animate.repeatCount = 15;
animate.motionPaths = paths;
animate.addEventListener( EffectEvent.EFFECT_REPEAT, animate_effectRepeatHandler );
animate.addEventListener( EffectEvent.EFFECT_END, animate_effectEndHandler );
}
private function animate_effectRepeatHandler( event:EffectEvent ):void
{
lblCounter.text = someCounter.toString();
someCounter++;
}
private function animate_effectEndHandler( event:EffectEvent ):void
{
lblCounter.text = someCounter.toString(); // Sometimes doesn't equal animate.repeatCount - 1
}
protected function button1_clickHandler(event:MouseEvent):void
{
if( !animate.isPlaying )
{
someCounter = 0;
animate.play();
}
}
]]>
</fx:Script>
<mx:Label id="lblCounter" horizontalCenter="0" bottom="50" width="150" height="50" textAlign="center" />
<mx:Button horizontalCenter="0" bottom="0" label="GO" width="150" height="50" click="button1_clickHandler(event)" />
</s:Application>
=新向量。();
路径推送(smp);
//创建动画
动画=新动画();
animate.easer=null;
animate.target=img;
animate.duration=150;
animate.repeatCount=15;
动画。运动路径=路径;
animate.addEventListener(EffectEvent.EFFECT\u REPEAT,animate\u effectRepeatHandler);
animate.addEventListener(EffectEvent.EFFECT\u END,animate\u effectEndHandler);
}
私有函数animate_effectRepeatHandler(事件:EffectEvent):无效
{
lblCounter.text=someCounter.toString();
someCounter++;
}
私有函数animate_effectEndHandler(事件:EffectEvent):无效
{
lblCounter.text=someCounter.toString();//有时不等于animate.repeatCount-1
}
受保护的功能按钮1\u clickHandler(事件:MouseeEvent):无效
{
如果(!animate.isplay)
{
someCounter=0;
播放动画();
}
}
]]>
我能想到的唯一一件事是,切换选项卡会导致某种性能问题,而Flash试图在重复计数期间遵守总持续时间,从而减少一些重复。除此之外,我还很茫然。嗨,韦斯利,谢谢你提供了如此清晰的描述和示例,我能够使用firefox或chrome进行复制。我相信你在评论中所说的基本上是正确的,当动画不在有焦点的选项卡中时,Flash会停止运行动画(并且看起来会重新绘制)。我正在对EffectEvent.EFFECT\u的源代码进行grep,以查看是否可以进一步了解何时调度此事件,以及为什么在选项卡没有焦点时调度不会发生。因此,出现了两个似乎相关的点(只有几个,但那些是为了添加监听器,因为它与调度事件无关),启动动画。接下来,在每个“迭代/循环”期间,都会在其中重新创建一个计时器对于延迟设置为repeatDelay且重复计数设置为1的动画,它会启动计时器,并在计时器处理程序中调度EFFECT_repeat事件,因此无论出于何种原因,当进程处于后台时,计时器似乎没有运行。(另一个可能相关的文件是AnimateInstance.as)我晚上不在工作,但我明天会查看推荐的文件和位置,以便跟进。奇怪的是,在我的制作代码中,即使选项卡无法恢复焦点,动画也会完成并触发一个效果结束事件。不管出于什么原因,它只是跳过了一些重复和/或sai的触发d事件。再次感谢,我明天会查看。我很欣赏这一见解,我甚至没有想到深入研究Adobe类。没问题,我总是要求这里的人发布他们使用的SDK版本,因为我最终不可避免地会查看SDK源代码,并希望能够使用相同的精确版本进行测试。幸运的是,y你很好地提供了一个很好的例子和大量的信息,不幸的是,我只是不知道为什么会发生这种情况。在我看来,框架的某些部分在后台运行时停止执行的方式只在flash player版本>9时才开始出现,我对此并不乐观,只是看起来是这样,不幸的是较新的SDK需要10个。