Playing with Drop Shadow Filter in AS3
Ok, so polygeek posted this neat little swf the other day. He had a swf which contained a TextField and he had applied a drop shadow to the text. Then he updated this so that when you moved your mouse cursor around, the drop shadow moved as if the cursor was the light source.
I though this was pretty cool, but polygeek only took the angle into account. I wanted to have the distance of the shadow set dynamically as well. I thought this was a perfect opportunity for me to do something in pure AS3. So here is what I wanted to do. Draw a border around the stage and set up cross hairs for middle just like polygeek did. Then center my text and apply the drop shadow. Then use an MouseMove event to update the drop shadow.
This is where the value of the Flash IDE comes in. I bet it took polygeek under 2 minutes to set up the display portion in his fla. I spent several hours leaning what a TextField is, how to format it, How to draw and why my lines where not where I thought they should be.
In the end I had a class with a constructor that was 50 lines long. I didnt like that at all. So I created a CrossHair object that is responsible for drawing the box and lines. Then I created a Label object that handled the formating of my TextField. Now things were looking like what I wanted.
The only thing I wanted to change from polygeeks example was to add a dynamic distance. That took me all of about 15 seconds.
In the end I am happy with the results. Just for fun as I was writing this I redid the example in mxml, utilizing the centering constraints and the styles to format the text. Whole process about a minute. So why bother with the AS3 version? The flex version of this application output a final swf that weighted in at just over 150 Kb. The AS3 version? 12 Kb. Twelve!
So while bandwidth is cheap, the AS3 version is considerably smaller. And next time it wont take me nearly as long as this time to put the AS3 example together. So what does this mean? Next time I need to put together an application or even a portion of the application, i will put serious consideration into wether or not I need the full mxml stack. Something I never really considered in the past.
If you want to check out my final code you can see it in my public svn repository here:

Where’s the SWF? I want a demonstration!
If you don’t have the Kimili plugin for WordPress then try it out:
http://kimili.com/plugins/kml_flashembed
It makes adding SWF files very easy.