<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright 2010 Chet Haase
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
    http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    viewSourceURL="srcview/index.html"
    width="322" height="346">
    
    <fx:Script>
        import mx.events.EffectEvent;
        import mx.effects.Effect;
        import spark.effects.animation.RepeatBehavior;
        
        private var animatingTargets:Object = new Object();
        
        private function animateHover(event:MouseEvent):void
        {
            if (animatingTargets[event.currentTarget] === undefined)
            {
                var effect:Effect;                
                if (rotationButton.selected)
                    effect = rotator;
                else
                    effect = mover;
                effect.target = event.currentTarget;
                animatingTargets[event.currentTarget] = effect;
                effect.play();
            }
        }
        private function effectEndHandler(event:EffectEvent):void
        {
            delete animatingTargets[event.effectInstance.target];
        }
    </fx:Script>
    <fx:Declarations>
        <s:Rotate3D id="rotator" angleYFrom="0" angleYTo="360"
            autoCenterTransform="true"
            effectEnd="effectEndHandler(event)"/>
        <s:Move3D id="mover" duration="250"
            zBy="-30" repeatCount="2"
            repeatBehavior="{RepeatBehavior.REVERSE}"
            effectEnd="effectEndHandler(event)"/>
    </fx:Declarations>
    <s:VGroup x="5" y="5">
        <s:HGroup>
            <s:RadioButton groupName="effectType" label="Rotation"
                id="rotationButton" selected="true"/>
            <s:RadioButton groupName="effectType" label="Movement"
                id="movementButton" selected="false"/>
        </s:HGroup>
        <s:Group>
            <s:layout>
                <s:TileLayout requestedColumnCount="3"/>
            </s:layout>
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
            <s:Button width="100" height="100" mouseOver="animateHover(event)"/> 
        </s:Group>
    </s:VGroup>
</s:Application>