Flash_and_Flex_03_2009

Flash DecalSheet System

Conclusion So that about covers the DecalSheet system. With DecalSheets , you can reduce your applicationsmemoryfootprintbyconsolidating smaller images into larger images. Any graphic you would embed in a class or place in a FLA’s library can be stored in a single DecalSheet or they can be spread over multiple DecalSheets depending on your needs. Since DecalSheets can be set up to only load when requested, you can load in application graphics exactly when you need them; cutting down the initial startup and load time. Finally you can reskin your entire application by simply changing the BitmapData of your DecalSheets at run time. This was a simplified version of the DecalSheet system found in Flash Camoflauge , graphics framework that I wrote. I have used this technique in my own projects for over a year now and don't think I can live without it. Hope you enjoy it as much as I do! JESSE FREEMAN My name is Jesse Freeman and I am Brooklyn based Flash Developer/Artist. I have been a working with Flash for over 7 years now and have been an interactive artist for about 10 years. Some of my clients include VW, Tommy Hilfiger, Heavy.com, MLB, the New York Jets, HBO and many more. I have a Flash Blog called FlashArtofWar.com as well as my portfolio FlashBum.com. I also run a New York City meetup called Flash Developer Happy Hour http://www.meetup.com/nyc-flash- developer-happy-hour/ that I invite anyone in the area to join.

On the 'Net • http://flashartofwar.com/downloads/decalsheet_src.zip

Around line 32:

protected function onDeactivate(event: Event):void { event.stopPropagation(); detach(); } We can test that the all the Decals have been disconnected by calling clear method on the DecalSheet and then trying to change the DecalSheet's BitmapData . You will see that the Decals no longer update themselves. Step 20 – Extending the DecalSheet System There are a lot of possibilities for extending the DecalSheet system. One interesting spinoff is to make TextField DecalSheet . You can easily create a DecalSheet Class that implements the IDecalSheet Interface but instead of using BitmapData would instead take a TextField and break it down into Decals. By using TextLineMetrics . Decals can be created by going line by line down a TextField or Character by Character. This is a great way to move text around the screen and avoid the distortion you sometime find when moving animating Dynamic TextFields . PaperVision is also another excellent place to use DecalSheets. Imaging being able to update a 3d model on the fly? By setting Decals as the textures you can update the DecalSheet's BitmapData to change the image of your 3d models.

protected function addListeners(target: IDecalSheet):void

Around line 37:

protected function removeListeners(target: IDecalSheet):void Now our Decal is completely typed to the DecalSheet's Interface instead of the actual Class. We have also enforced that any Class that wants to use the Decal Class must implement all of the same public functions as the DeccalSheet . Step 19 – Clear Decals from the DecalSheet The last feature we will add is the ability to clear a DecalSheet of Decals and disconnect any instantiated Decal that are linked to the DecalSheet . To get started lets add the following method to the DecalSheet , see (Listing 12). Now when we call the clear method on the DecalSheet we dispatch a Deactivate Event and clear the Dictonary and Array. Now we need to add an Event listener to the Decal. In the Decal Class replace the addListeners and removeListeners function with the following, see (Listing 13). We will also need to add the following method after the onChange function:

A D V E R T I S E M E N T

03/2009 (5)

37

Made with FlippingBook HTML5