EFFECT_REPEAT не срабатывает на каждой итерации экземпляра Animate при потере фокуса - PullRequest
0 голосов
/ 01 марта 2012

Я не уверен, что этот заголовок достаточно описательный, но вот основная проблема.У меня есть экземпляр spark.effects.Animate, повторяющийся n раз со слушателем события EFFECT_REPEAT.В слушателе этого события я увеличиваю переменную.Логика будет диктовать, что если переменная начинается с 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...