Search code examples
actionscript-3apache-flexflex3mxmleffects

Check if any of effects is playing in Flex 3


I have some effects which I use in my Flex app... They are all declared within mxml tags... For example:

<mx:Fade id="fadeIn" alphaTo="1" duration="500"/>
<mx:Fade id="fadeOut" alphaTo="0" duration="500"/>
<mx:Move id="moveEffect" duration="500"/>
<mx:Rotate id="rotateEffect" duration="500"/>

Usually, when I trigger some effect, I want to disable all interaction if any of effects is playing, so I would like to know is there a way to check such thing in actionscript besides

if (!fadeIn.isPlaying && !fadeOut.isPlaying && !moveEffect.isPlaying && !rotateEffect.isPlaying)

Thanks a lot for help!


Solution

  • Wrap your effects with Array or Vector:

    <fx:Declarations>
        <fx:Vector id="effects" type="mx.effects.Effect">
            <mx:Fade id="fadeIn" alphaTo="1" duration="500"/>
            <mx:Fade id="fadeOut" alphaTo="0" duration="500"/>
            <mx:Move id="moveEffect" duration="500"/>
            <mx:Rotate id="rotateEffect" duration="500"/>
        </fx:Vector>
    </fx:Declarations>
    
    private function isEffectPlaying():Boolean
    {
        for (var i:int = 0; i < effects.length; i++)
        {
            if (effects[i].isPlaying)
                return true;
        }
        return false;
    }