<?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"
    mouseMove="updateShadow(event)"
    viewSourceURL="srcview/index.html"
    width="500" height="370">
    
    <fx:Script>
        <![CDATA[
        private function updateShadow(event:MouseEvent):void
        {
            // compute the angle the light source (mouse position)
            var tempX:Number = event.stageX - (width / 2);
            var tempY:Number = event.stageY - (height / 2);
            var angle:Number;
            if (tempX != 0)
                angle = 180 * Math.atan(tempY / tempX) / Math.PI;
            else
                angle = (tempY < 0) ? -90 : 90;
            if (tempX < 0)
                angle += 180;
            // now set the shadow angle to be opposite the light source angle
            shadow.angle = angle + 180;
            
            // Calculate the distance from the center
            var dist:Number = Math.sqrt(tempX * tempX + tempY * tempY);
            var maxDist:Number = Math.sqrt(width * width + height * height) / 2;
            shadow.distance = 15 * (dist / maxDist);
        }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:DropShadowFilter id="shadow" strength=".5"/>
    </fx:Declarations>
    <s:TileGroup x="20" y="20" verticalGap="20" horizontalGap="20" requestedColumnCount="4">
        <s:Button width="100" height="50" filters="{[shadow]}" 
                  opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
        <s:Button width="100" height="50" filters="{[shadow]}" opaqueBackground="true"/>
    </s:TileGroup>
</s:Application>