Note: This learning guide introduces graphic effects in Adobe Flash CS4 Professional and provides you with tools for developing your skills. Always consult Flash CS4 Professional Help first when learning to use new features.
Adobe Flash CS4 Professional provides a number of features for producing impressive graphic effects. These features, along with the improved workflow of Flash CS4, open up an endless list of effect and production possibilities.
Besides the drawing features and video capabilities, these graphic effects make up a category of tools promoting expressiveness—the ability to enhance the look and feel of your project.
Here is a summary of a few of these important features:
z property and rotationX, rotationY, and rotationZ properties.You can apply filters and blend effects in either Flash CS4 Professional using the Property panel during authortime or with ActionScript code at runtime.
Note: The ActionScript samples in this article are written in ActionScript 3 and must be used within an ActionScript 3 file. See the Flash 8 version of this article for samples that can be used in an ActionScript 1 or ActionScript 2 file. Also, if you have not upgraded yet to the latest version of Flash, you can check out the Flash CS3 version of this article.
To follow along with this learning guide, you will need to install the following software:
This article assumes you are familiar with the Flash Professional workspace and have a basic knowledge of working with FLA files. An intermediate knowledge of ActionScript is required for the sections of this learning guide that discuss how to create graphic effects programmatically.
Filters add interesting visual effects to text, buttons, and movie clips. Filters are most often associated with applying drop shadows, blurs, glows, and bevels to graphic elements. A feature unique to Adobe Flash Professional is that you can animate the filters using motion tweens. For example, if you create a ball with a drop shadow, you can simulate the look of the light source moving from one side of the object to another by changing the position of the drop shadow from its beginning and ending frames in the Timeline.
After you apply a filter, you can change its options at any time or rearrange the order of filters to experiment with combined effects. You can enable or disable filters or delete them in the Property inspector. When you remove a filter, the object returns to its previous appearance. You can view the filters applied to an object by selecting it; doing so automatically updates the filters list in the Property inspector for the selected object.
This section describes the process of adding a filter to a movie clip instance and creating a simple drop shadow effect.
You can apply one or more filters to selected objects using the Property inspector. Each time you add a new filter to an object, it is added to the list of applied filters for that object in the Property inspector. You can apply multiple filters to an object, as well as remove filters that have been previously applied. Applying different filters affects the appearance of a movie clip instance (see Figure 1).
Figure 1. Various examples of filter effects applied to movie clip instances
Click the Add filter (+) button in the lower left of the Property inspector and select a filter from the Filters pop-up menu (see Figure 2). The filter you select is applied to the object and the controls for the filter settings appear in the Property inspector.

Figure 2. Adding a filter to the Filter tab in the Property inspector
Notice that the filter's adjustable parameters fill the filter list area. Experiment with the filter settings until you get the look you want.
You can create a filter settings library that allows you to easily apply the same filter or sets of filters to an object. Flash CS4 stores the filter presets you create in the Property inspector under the Filters area, seen when a compatible object is selected on the Stage. You can save, delete, assign, or rename presets by clicking the Presets button at the bottom of the Property inspector.
Note: Alt-click the eyeball icon to toggle the enable state of the other filters in the list To the opposite state of the selected filter.
At this point, you may want to try applying a basic filter effect yourself. An easy example to start with is applying a drop shadow, so try it out by using the following steps.
Use the Drop Shadow filter's Hide object option to create a more realistic look by skewing the shadow of an object (see Figure 3). To achieve this effect, you need to create a duplicate movie clip, button, or text object, apply a drop shadow to the duplicate, and use the Free Transform tool to skew the duplicate object's shadow.

Figure 3. Skewing the Drop Shadow filter to create a more realistic shadow
Apply the Drop Shadow filter to the duplicated movie clip or text object, and select the object option (see Figure 4). The duplicated object is hidden from view, leaving only the skewed shadow.

Figure 4. The Hide object option of the Drop Shadow filter can be useful for creating realistic shadow effects.
For more information on working with filters during authoring, see the About filters section of the Using Flash CS4 Professional online documentation.
You can apply filters using the Flash CS4 user interface, or you can apply filters or groups of filters to movie clips, buttons, or text fields using ActionScript.
If you use ActionScript to apply the filters to an instance, you can also use a displacement map filter or convolution filter, which are not available in the Flash user interface. Filters are applied to the vector definitions, so there is no file size overhead related to storing a bitmap image within the SWF file. You can also write ActionScript that modifies an existing filter applied to a text field, movie clip, or button to create dynamic effects.
This section describes the process of adding a filter to a movie clip instance using ActionScript.
Let's try applying a basic filter effect using ActionScript code. An easy example to get started with involves applying a bevel filter. In the steps below, we've included a code example.
import flash.filters.BevelFilter;
// define a bevel filter
var bevel:BevelFilter = new BevelFilter(4, 45, 0x99CCFF, 1, 0x003399, 1, 10, 10, 2, 3);
// set strength
bevel.strength = 5;
// apply the filter to my_mc
my_mc.filters = [bevel];
For information on the parameters you can pass to the bevel filter, see the BevelFilter section of the Flash CS4 Professional ActionScript 3 Language Reference.
Applying different filters with code works pretty much the same way. However, different filters need different information when you apply the filter. For example, the color matrix filter requires an array. You can use the color matrix filter to modify the brightness of an instance, as the following example demonstrates.
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
import flash.filters.ColorMatrixFilter;
var pictLdr:Loader = new Loader();
var pictURL:String = "http://www.helpexamples.com/flash/images/image2.jpg";
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
addChild(pictLdr);
function imgLoaded(event:Event):void
{
var myElements_array:Array = [1, 0, 0, 0, 10,
0, 1, 0, 0, 100,
0, 0, 1, 0, 100,
0, 0, 0, 1, 0];
var myColorMatrix_filter:ColorMatrixFilter = new ColorMatrixFilter(myElements_array);
pictLdr.content.filters = [myColorMatrix_filter];
}
This code dynamically loads a JPEG image using a Loader instance. After the image has completely loaded and has been placed on the Stage, the instance's brightness is altered by using a color matrix filter.
For more information on the color matrix, see the ColorMatrixFilter section of the Flash CS4 Professional ActionScript 3.0 Language Reference.
After you apply a filter, you can manipulate it using ActionScript, such as adjusting the filter properties or animating the filter. For more information, see the Filtering display objects section of Programming ActionScript 3.0 for Flash.
Note: There are two additional filters that you can apply using ActionScript code, but they are not available using the Flash CS4 user interface: the convolution filter and the displacement map filter. For information on these filters see the following sections of the Flash CS4 Help pages:
For more information on the variety of filters available, please see the Available display filters section of Programming ActionScript 3.0 for Flash.
You access the array of filters applied to an object through standard
ActionScript calls using the DisplayObject.filters property. This returns an array that contains each filter object currently
associated with the movie clip. By adding more than one filter to an objects
filters array, you can apply multiple effects. The effects will be applied in
the order they are listed in the array.
It's important to note that setting the filters property duplicates the filters array that you pass into it (demonstrated in
the following example) and does not store the filter as a reference. When
getting the filters property, it returns a new copy of the array. One negative implication of this
approach is that the following code will not work:
// This will not work my_mc.filters[0].push(myFilter);
Because the previous code snippet returns a copy of the filters array, it modifies the duplicate. The following code example adds a blur filter to the end of an object's existing filter list:
// This will work: import flash.filters.BlurFilter; var filterList:Array = myClip.filters; filterList.push(new BlurFilter(3,3,2)); myClip.filters = filterList;
The advantage of this is that you can copy the filters from one object, modify them and apply them to another object without worrying about affecting the original object's filters.
By adding more than one filter to an object's filters array you can
apply multiple effects. The filters will be applied in the order they are
listed in the array. This returns an array that contains each filter object
currently associated with the movie clip. Each filter has a set of properties
unique to it. The filters can be accessed and modified just like a regular
array object, although getting and setting the filters using the filters property returns a duplicate of
the filters object instead of a reference.
// This will not work my_mc.filters[0].blurX = 20;
Because the previous code snippet returns a copy of the filters array, it
modifies the duplicate. In order to modify the blurX property, you need to use the following
ActionScript code instead:
// This will work var filterList:Array = my_mc.filters; filterList[0].blurX = 20; my_mc.filters = filterList;
The following example blurs an image based on the current position of the
mouse pointer on the Stage. Whenever the mouse cursor moves horizontally or
vertically, the blurX and blurY properties of the blur filter are
modified accordingly.
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;import flash.filters.BlurFilter;
var pictLdr:Loader = new Loader();
var pictURL:String = "http://www.helpexamples.com/flash/images/image2.jpg";
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
addChild(pictLdr);
function imgLoaded(event:Event):void{
pictLdr.filters = [new BlurFilter(10, 10, 2)];
pictLdr.x = (stage.stageWidth - pictLdr.width) / 2;
pictLdr.y = (stage.stageHeight - pictLdr.height) / 2;
pictLdr.addEventListener(MouseEvent.MOUSE_MOVE, redrawEffect);
}
function redrawEffect(event:MouseEvent):void{
var tempFilter:BlurFilter = pictLdr.filters[0];
tempFilter.blurX = Math.floor((event.stageX / stage.stageWidth) * 100);
tempFilter.blurY = Math.floor((event.stageY / stage.stageHeight) * 100);
pictLdr.filters = [tempFilter];
}
flash.filters.BlurFilter class and other necessary packages so that you don't have to use the fully
qualified class name when you refer to each class. The second section loads an
image and assigns it to a display object with its initial settings. The third
section of code responds to the mouse movement on the Stage and adjusts the
blur accordingly.blurX property. Moving the mouse
cursor vertically along the y-axis modifies the blur filter's blurY property. The closer the
mouse cursor is to the upper left corner of the Stage, the less blurring
will be applied to the movie clip.For more examples of working with filters at runtime, check out the Filter Workbench sample in the Programming ActionScript 3.0 for Flash online documentation. You can download the source files from the following link:
You can animate movie clips that have filters applied to them. In Flash CS4, tweens are attached directly to the objects they are animating. Keyframes along the timeline show at which points the characteristics of the animating object have changed—position, transformations, and filters included. By creating a motion tween and changing the filter properties at different keyframes, you can easily animate filters to create light source effects, highlights, bevels, and distortions.
This section describes the process of animating a filter effect using the Flash workspace in one example and ActionScript in another.
Follow these steps to add a filter manually in Flash:
Right-click frame 24 of the Blur X row of the Glow filter properties. Insert a keyframe (see Figure 5).
Figure 5. The Motion Editor panel is a new addition to Flash CS4 which allows you to easily edit all aspects of your tweened animations.
Note: Flash CS4 Professional supports advanced control over every editable property in a tween with the Motion Editor. For more information, please see the Editing property curves with the Motion Editor section of Using Flash CS4 Professional.
You can use ActionScript, such as the Tween class, to animate filters at runtime. This approach allows you to apply interesting, animated effects to your Flash applications.
In the first example, you apply a Glow filter to a movie clip instance.
Using an enterFrame event
handler, you animate the amount of glow that's applied to the movie clip.
import flash.filters.GlowFilter;
var dir:Number = 1;
my_mc.blur = 10;
my_mc.filters = [new GlowFilter()];
my_mc.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(event:Event):void
{
my_mc.blur += dir;
if ((my_mc.blur >= 30) || (my_mc.blur <= 10)) {
dir *= -1;
}
var filter_array:Array = my_mc.filters;
filter_array[0].blurX = my_mc.blur;
filter_array[0].blurY = my_mc.blur;
my_mc.filters = filter_array;
}
This code applies a glow filter to your movie clip
instance on the Stage and defines an enterFrame event handler, which is responsible for animating the filter effect. The enterFrame event handler animates the
glow filter between a blur of 10 and 30 pixels. After the animation is greater
than or equal to 30, or less than or equal to 10, the direction of the
animation reverses.
Here's an important thing to remember as you apply filters to movie clips in your files: The type, number, and quality of filters you apply to objects can affect the performance of SWF files as you play them. The more filters you apply to an object, the greater the number of calculations Flash Player must process to display correctly the visual effects you've created. For this reason, Adobe recommends that you apply only a limited number of filters to a given object.
The actual impact at runtime is heavily dependent on the screen area that the filters are being applied to and how often the player has to redraw the filter. The player will automatically cache movie clips with filters applied as bitmaps to avoid having to redraw them each frame. When a movie clip is modified by rotating, resizing, or otherwise changing its appearance, the player redraws the clip and its effects. Note that translating (moving) a movie clip does not cause a redraw. For more information on bitmap caching, see the section on Runtime bitmap caching.
Each filter includes controls that let you adjust the strength and quality of the applied filter. Using lower settings improves performance on slower computers. If you are creating content for playback on a wide range on computers, or are unsure of the computing power available to your audience, set the quality level to low in order to maximize playback performance.
Tip: When applying a blur filter with
ActionScript, using values for blurX and blurY which are powers of two (such as
2, 4, 8, 16, and 32) can be computed faster and offer the benefit of a 20–30%
performance improvement.
Try to animate different filter types to see the effects. Pay attention to the performance and rendering quality as you experiment.
To learn more about animation optimization and to see what's possible with animated filters, check out Grant Skinner's article, Varicose-g: High-performance graphics in Flash.
Blend modes create composite images by blending the color of pixels in overlapping objects. Blending enables you to create unique effects by blending the colors in overlapping movie clips, as well as adding a dimension of control to the opacity of objects and images. You can use blend modes to create highlights or shadows that let details from an underlying image show through, or to colorize a desaturated image.
A blending mode contains these elements:
This section describes the process of applying blend modes to instances using the Flash CS4 workspace and ActionScript.
Because blend modes depend on both the color of the object to which you're applying the blend and the underlying color, you'll need to experiment with different colors to see what the result will be. Try experimenting with the different blend modes to achieve the effect you want.
Flash CS4 provides the following blend modes:
Note: The Erase and Alpha blend modes require that a blend mode other than Normal be applied to the parent movie clip.
Different blend modes affect the appearance of an image in different ways. Be aware that the resulting effect of a blend mode may be considerably different, depending on the color of the underlying image and type of blend mode you apply (see Figure 6).
Figure 6. Examples of blend modes
You use the Property inspector to apply blend modes to selected movie clips.
You might need to experiment with both the color and transparency settings of the movie clip and then try applying different blend modes to achieve the effect you want. For information on adjusting the color of a movie clip, see the Applying blend modes section of Using Flash CS4 Professional.
You can also apply blend modes to instances using ActionScript code. For example, you can apply the difference blend mode using the following code.
Type the following ActionScript on Frame 1 of the Timeline:
var pictLdr:Loader = new Loader();
var pictURL:String = "http://www.helpexamples.com/flash/images/image1.jpg";
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
addChild(pictLdr);
function imgLoaded(event:Event):void
{
pictLdr.blendMode = "difference";
}
Note: The code sample above is written in ActionScript 3 and must be used within an ActionScript 3 file (the default Flash CS4 setting).
Then select Control > Test Movie to test the document.
To see how different blend modes are applied to an image, follow along with the next example. The code below loads a dynamic image and allows you to apply different blending modes to the image by selecting a blending mode from a combo box on the Stage.
import fl.data.DataProvider;
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
// Create a list of mode typesvar
var blendMode_dp:Array = new Array();
blendMode_dp.push({data:"add", label:"add"});
blendMode_dp.push({data:"alpha", label:"alpha"});
blendMode_dp.push({data:"darken", label:"darken"});
blendMode_dp.push({data:"difference", label:"difference"});
blendMode_dp.push({data:"erase", label:"erase"});
blendMode_dp.push({data:"hardlight", label:"hardlight"});
blendMode_dp.push({data:"invert", label:"invert"});
blendMode_dp.push({data:"layer", label:"layer"});
blendMode_dp.push({data:"lighten", label:"lighten"});
blendMode_dp.push({data:"multiply", label:"multiply"});
blendMode_dp.push({data:"normal", label:"normal"});
blendMode_dp.push({data:"overlay", label:"overlay"});
blendMode_dp.push({data:"screen", label:"screen"});
blendMode_dp.push({data:"subtract", label:"subtract"});
// Initialize the combobox
blendMode_cb.dataProvider = new DataProvider(blendMode_dp);
blendMode_cb.addEventListener(Event.CHANGE,changeHandler);
// Create an event handler for the combobox
function changeHandler(event:Event):void {
pictLdr.blendMode = event.target.selectedItem.data;
}
// Create a colored rectangle for the overlay
var rect:Shape = new Shape();
rect.graphics.beginFill(0xFF0000);
rect.graphics.moveTo(100,100);
rect.graphics.lineTo(350,100);
rect.graphics.lineTo(350,350);
rect.graphics.lineTo(100,350);
rect.graphics.lineTo(100,100);
addChild(rect);
// Load an image to view the modes
var pictLdr:Loader = new Loader();
var pictURL:String = "http://www.helpexamples.com/flash/images/image1.jpg";
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
addChild(pictLdr);
// Layout the image when it has downloaded
function imgLoaded(event:Event):void
{
pictLdr.x = (stage.stageWidth - pictLdr.width) / 2;
pictLdr.y = (stage.stageHeight - pictLdr.height) / 2;
}
This ActionScript code populates the combo box with each type of blending mode, so the user can view each effect on the dynamically loaded image. A colored rectangle is drawn behind an image loaded from the server. The two images create a blending effect which displays differently each time a new blending mode is selected in the combo box.
Flash Player 10 introduces the ability to assign a Pixel Bender shader as a blend mode to produce a new range of visual effect possibilities. Please see Using a shader as a blend mode in the Programming ActionScript 3.0 for Flash online documentation for more information.
Bitmap images can be manipulated in the Flash workspace by positioning and sizing them. Graphic effects can be applied directly to bitmap instances by using the BitmapData class or a Pixel Bender shader function in ActionScript. In addition, you can work with bitmap caching to improve graphics rendering performance in some situations.
This section describes how to create bitmap effects using ActionScript. The first example shows how to use the BitmapData class and the second example shows how to create a Pixel Bender shader. You'll also take a look at best practices for bitmap caching.
The BitmapData class enables you to manipulate bitmap data within an existing image, to convert vector images into bitmaps, or to create new bitmaps from scratch on the fly. By manipulating a bitmap instance directly using ActionScript, you can create very complex images and effects without incurring the overhead of constantly redrawing the content from vector data in Adobe Flash Player. The BitmapData class can be used for special effects on images, on-demand video, and webcam video.
A BitmapData object contains an array of pixel data. This data can either represent a fully opaque bitmap or a transparent bitmap containing alpha channel data. Both types of BitmapData objects are stored as a buffer of 32-bit integers. Each 32-bit integer determines the properties of a single pixel in the bitmap. The 32-bit integer is a combination of four 8-bit channel values (from 0 to 255) that describe the alpha transparency and the red, green, and blue (ARGB) values of the pixel.
Just as RGB colors are typically represented as six-digit hex numbers (for example, red is 0xFF0000), ARGB is represented as an eight-digit hex number, where the first two digits represent the alpha channel, the second two represent the red channel, and so on (for example, 50% opaque red would be represented as 0x80FF0000).
The following procedure dynamically loads a JPEG image onto the Stage and creates a noise effect, similar to static on a television, using the BitmapData class. The noise effect is redrawn with a random pattern every 100 milliseconds (1/10 of a second). Moving the mouse along the x-axis and y-axis affects how much static is drawn at every interval.
import flash.display.Bitmap;
import flash.display.BitmapData;
// Load image
var pictLdr:Loader = new Loader();
var pictURL:String = "http://www.helpexamples.com/flash/images/image1.jpg";
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
addChild(pictLdr);
// Create bitmap data object
var noiseBmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true);
var noiseBm:Bitmap = new Bitmap(noiseBmd);
addChild(noiseBm);
// Initialize image when loaded
function imgLoaded(event:Event):void
{
pictLdr.x = (stage.stageWidth - pictLdr.width) / 2;
pictLdr.y = (stage.stageHeight - pictLdr.height) / 2;
pictLdr.addEventListener(MouseEvent.MOUSE_MOVE, redrawEffect);
}
// Draw effect!
function redrawEffect(event:MouseEvent):void
{
var low:Number = 30 * event.stageX / stage.stageWidth;
var high:Number = 200 * event.stageY / stage.stageHeight;
noiseBmd.noise(Math.round(Math.random() * 100000), low, high, 8, true);
}
This code creates an image with an overlying bitmap data instance. When the mouse's position changes, the coordinates are used to calculate changes in the applied noise effect.
Moving the mouse along the horizontal x-axis affects the low parameter; moving the mouse pointer along the vertical y-axis affects the high parameter.
The Pixel Bender Toolkit lets you create custom effects called shaders. Shaders can be used to create advanced graphic effects with image and data processing in SWF files exported to Adobe Flash Player 10 or later.
Adobe Pixel Bender is a programming language used to manipulate image content at the pixel level using a shader function. The shader function is called to render an effect on each pixel in the image. Where possible, the shader function is called for multiple pixel coordinates at the same time. This improves performance over the capabilities of the BitmapData object.
The Pixel Bender Toolkit is included with the Creative Suite 4 bundle. It's an easy-to-use interface for creating Pixel Bender shader functions for use in your SWF applications. With Pixel Bender, you will commonly create the following:
Working with Pixel Bender shaders generally falls into one of two categories: creating the Pixel Bender filter in the Pixel Bender Toolkit and applying the Pixel Bender filter to the SWF content in ActionScript code.
import flash.display.*;
var loader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest("invertRGB.pbj"));
function onLoadComplete(event:Event):void
{
var rectangle:Shape = new Shape();
var g1:Graphics = rectangle.graphics;
var c1:Array = [0x336600, 0x80ff00];
var a1:Array = [255, 255];
var r1:Array = [100, 255];
var m1:Matrix = new Matrix();
m1.createGradientBox(300, 200);
g1.beginGradientFill(GradientType.LINEAR, c1, a1, r1, m1);
g1.drawEllipse(0, 0, 300, 200);
g1.endFill();
addChild(rectangle);
var shader = new Shader(loader.data);
var shaderFilter:ShaderFilter = new ShaderFilter(shader);
rectangle.filters = [shaderFilter];
}
This code loads the invertRGB kernel and applies it as a filter to the gradient shape. The effect inverts the green gradient and changes the color. Comment out the second-to-last line to see the actual color of the gradient.
Note: Pixel Bender shaders can be used for image processing or data processing.
As your designs grow in size, you'll need to consider performance and optimization. When you have content that remains static (such as a rectangle movie clip), Flash Player does not optimize the content. Therefore, when you change the position of the rectangle movie clip, or when other elements change in its general vicinity, the SWF redraws the entire rectangle in Flash Player 7 and earlier.
In Flash Player 8 or later, you can cache specified movie clips and buttons to improve the performance of your SWF file. The movie clip or button is a surface, essentially a bitmap version of the instance's vector data, which is data that you do not intend to change much over the course of your SWF file. Since instances with caching turned on are not continually redrawn by Flash Player as the SWF file plays, the SWF file renders more quickly.
A cached bitmap is not created, even if you set it to cache, if one or more of the following occurs:
Applying bitmap caching is not always recommended, because in certain circumstances it can negatively affect SWF file performance. Bitmap caching also slightly increases RAM usage at runtime because the player must maintain both the vector data and cached bitmap in memory.
You can use ActionScript to enable caching or scrolling, as well as to control backgrounds. You can use the Property inspector to enable caching for a movie clip instance. If you do not want to use ActionScript, you can select the Cache as bitmap caching option in the Property inspector instead.
If you use ActionScript, you can use three properties for button and display
object instances. Using these properties, you can specify bitmap caching, set a
background color for a display object (opaqueBackground), and set a property
that allows your users to quickly scroll the movie clip content (scrollRect).
To cache a display object instance, you need to set the cacheAsBitmap property to true. After
you set the cacheAsBitmap property to true, you might notice that the instance automatically pixel-snaps
to whole coordinates. When you test the SWF file, you should notice that
complex vector animation renders much faster.
Select Frame 1 of the Timeline and then add the following ActionScript to the Actions panel:
// Turn on bitmap caching for the large background my_mc.cacheAsBitmap = true;
By caching the complex vector background graphic, the movie animates over the top of it without having to redraw the image during each frame of movement.
Note: You cannot apply caching directly to text fields. If you wish to apply caching to a text field, you can place a text field within a movie clip first, and then apply caching to the movie clip that contains the text field.
For more information on working with bitmaps, please see the Working with bitmaps section of the Programming ActionScript 3.0 for Flash online documentation.
For more information on working with Pixel Bender, please see the Working with Pixel Bender shaders section.
Font rendering in Adobe Flash Player controls the way your text appears in a SWF file—that is, how it is rendered (or drawn) at runtime. Flash CS4 offers the advanced anti-aliasing options available in ActionScript 2 and ActionScript 3, as well as the new Flash Text Engine (FTE), which gives developers far greater control over text rendering and layout.
This section describes how to work with anti-alias text controls in the TextField class and the new controls in the Flash Text Engine.
Flash Player 8 and later offers two types of anti-aliasing: normal and advanced. The advanced font rendering technology helps make text appear legible and clear at small to regular font sizes, such as when you apply advanced anti-aliasing to your text fields. You can enable advanced anti-aliasing using either the Flash CS4 authoring tool or ActionScript. The improved capabilities mean that embedded text appears at the same level of quality as device text, and fonts appear the same on different platforms.
Anti-aliasing results in smooth text so that the edges of characters displayed onscreen look less jagged—which can be particularly helpful when you want to display text at small sizes. Anti-aliasing is supported for static, dynamic, and input text if the user has Flash Player 7 or later.
Advanced and custom anti-alias features support the following:
Advanced and custom anti-alias features do not support the following:
Note: When text is animated, the player turns off advanced anti-aliasing to improve the appearance of your text while it's moving. After the animation is complete, anti-aliasing is turned back on. Subpixel rendering is also disabled for fields with advanced anti-aliasing when they are cached as bitmaps, have a filter applied to them, or are drawn into a BitmapData object.
There are five different font rendering options available in Flash CS4. To choose an option, select the text field and open the Property inspector. Select an option from the Font rendering method pop-up menu:
When you open a FLA file created for use with Flash Player 7 or earlier, the Property inspector sets the anti-alias option to its equivalent anti-aliasing option from Flash MX 2004 to the file's text.
Tip: Advanced anti-aliasing is not recommended for very large fonts (larger than 48 points).
You can also apply Anti-alias for Readability or Custom Anti-alias using
ActionScript, which is essential when you need more control over the
appearance, content, and formatting of your text fields. Advanced anti-aliasing
is available only in Flash Player 8 and later, and can be used only if you
embed the font in the library and have the text field's embedFonts property set to true. For
Flash Player 9, the default setting for text fields created using ActionScript
is normal.
To set values for the TextField.antiAliasType property, use the following string values:
// Create the field's format
var format:TextFormat = new TextFormat();
format.color = 0x336699;
format.size = 10;
format.font = "Arial";
// Create the text field
var myText:TextField = new TextField();
myText.embedFonts = true;
myText.autoSize = TextFieldAutoSize.LEFT;
myText.antiAliasType = AntiAliasType.ADVANCED;
myText.defaultTextFormat = format;
myText.selectable = false;
myText.mouseEnabled = true;
myText.text = "Hello World";
myText.addEventListener(MouseEvent.CLICK, clickHandler);
addChild(myText);
// Toggle the antialias mode when the text is clicked on
function clickHandler(event:Event):void
{
if( myText.antiAliasType == AntiAliasType.NORMAL ){
myText.antiAliasType = AntiAliasType.ADVANCED;
}else{
myText.antiAliasType = AntiAliasType.NORMAL;
}
}
The previous code is split into four key areas. The first block of code creates a new TextFormat object, which specifies a font and font size to be used for a text field that will be created shortly.
The second block of code creates a new text field
with the instance name myText. In order for the font to be properly embedded,
you must set embedFonts to
true for the text field instance. The code also sets the text formatting for
the new text field to the TextFormat object that you created earlier.
The third, and final, block of code defines the click handler, which toggles the antiAliasType property between normal and advanced.
Clicking the text field switches the anti-alias type from normal (the default) to advanced. When you are dealing with text
fields with a smaller font size, setting the anti-aliasing to advanced can
dramatically improve the readability of the text.
Tip: Advanced anti-aliasing allows font faces to be rendered at very high quality at small sizes. It is best used with applications that include a great deal of small text. Advanced anti-aliasing is not recommended for very large fonts (larger than 48 points).
Flash Player 10 includes the new Flash Text Engine (FTE) classes, which allow for far more complex text formatting operations including control over text metrics, formatting, and bidirectional justifications. The FTE classes also include improved support for multilingual applications, such as those that switch between Latin text and multibyte Asian text.
The following example shows how the justification can be precisely controlled in a simple text block. In this case, all lines in the text block are justified except the last line.
import flash.text.engine.*;
import flash.display.Sprite;
var str:String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " +
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut " +
"enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " +
"aliquip ex ea commodo consequat.";
var format:ElementFormat = new ElementFormat();
var textElement:TextElement = new TextElement(str, format);
var spaceJustifier:SpaceJustifier = new SpaceJustifier("en", LineJustification.ALL_BUT_LAST);
var textBlock:TextBlock = new TextBlock();
textBlock.content = textElement;
textBlock.textJustifier = spaceJustifier;
var textLine:TextLine = textBlock.createTextLine(null, 150);
var yPos = 20;
while( textLine )
{
addChild(textLine);
yPos += textLine.textHeight + 2;
textLine.x = 15;
textLine.y = yPos;
textLine = textBlock.createTextLine(textLine, 150);
}
Notice that the SpaceJustifier class allows you to set the justification to all but the last line with an indicator that the font being justified is in the English language (en). The FTE gives you element-, line-, and block-level access to font rendering.
For more information on programming text fields, please see the Using the TextField class section of the Help pages.
For more information on working with the new Flash Text Engine, please see the Using the Flash Text Engine section of the Help pages.
Among the many workflow improvements included with Flash CS4, there is a handful of new graphic effects features that provide new options for animation and graphic production. These features are supported in ActionScript 3 files and require Flash Player 9, or Flash Player 10 in some cases.
This section provides an overview of many of the new graphics related features in Flash CS4.
The Bone tool in Flash CS4 lets you create armatures using inverse kimematics. An armature creates coordinated movements within a chain of connected parts. The parts within the armature can be sections of a drawing object or multiple symbol instances.
Note: You can work with armatures with either the Authortime or Runtime setting. In Authortime mode, you can create tweened animations by creating pose frames on the armature layer.
You can create armatures in the Flash CS4 authoring tool for Flash Player 10 and later. For more information, please see the Working with inverse kinematics section of Programming ActionScript 3 for Flash, as well as the Animating with the Bone tool section of Creating animation in ActionScript 3.
Flash CS4 and Flash Player 10 support 3D animation of 2D objects using the new z property and rotationX, rotationY, and rotationZ properties of the DisplayObject class. You can access these properties in ActionScript 3 or by using the 3D Rotation Tool (W) in Flash CS4.
One exciting and relatively new feature is the ability to create a motion tween along the Timeline and then copy and paste the exact tweening effect on another object. This feature can act as a consistency tool and offers an easy and efficient method for applying animation effects across a movie or multiple movies.
Note: The process for creating tweened animations has changed in Flash CS4, but the process for copying a tween is the same as it was in Flash CS3.
Select the options from the original tween that you want to paste and click the Apply button to apply the effect (see Figure 7).

Figure 7. The Motion Presets panel is a new feature in Flash CS4 enabling you to choose animation presets or create custom presets.
Copying a motion tween as ActionScript 3 allows you to paste the effect as ActionScript. In Flash CS3, the resulting ActionScript uses descriptive data written in XML format along with the ActionScript 3 Animator class to dynamically create the animation effect. In Flash CS4, the resulting ActionScript uses the AnimatorFactory class to produce the effect without XML. These approaches offer a quick way to generate animation in your code-based work or as a consistent way to quickly apply motion animation settings to a number of objects without using the Timeline.
Note: The Animator and AnimatorFactory classes are available in Flash Player 9 and later. The Animator3D and AnimatorFactory3D are available in Flash Player 10 and later for 3D tweens.
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import flash.filters.*;
import flash.geom.Point;
var __motion_sq_2:MotionBase;
if(__motion_sq_2 == null) {
import fl.motion.Motion;
__motion_sq_2 = new Motion();
__motion_sq_2.duration = 24;
// Call overrideTargetTransform to prevent the scale, skew,
// or rotation values from being made relative to the target
// object's original transform.
// __motion_sq_2.overrideTargetTransform();
// The following calls to addPropertyArray assign data values
// for each tweened property. There is one value in the Array
// for every frame in the tween, or fewer if the last value
// remains the same for the rest of the frames.
__motion_sq_2.addPropertyArray("x", [0,5.63511,11.3635,17.3335,23.9381,32.789,45.597,55.1297,63.5817,71.8295,80.1171,88.5647,97.1921,106.035,115.079,124.33,133.779,143.438,153.271,163.286,173.464,183.794,194.295,204.95]);
__motion_sq_2.addPropertyArray("y", [0,-12.9125,-25.8012,-38.585,-51.0339,-61.9071,-60.1564,-49.8042,-38.5181,-27.078,-15.6877,-4.38936,6.75406,17.75,28.5647,39.203,49.6592,59.9546,70.0589,79.9907,89.7427,99.3154,108.736,118]);
__motion_sq_2.addPropertyArray("scaleX", [1.000000]);
__motion_sq_2.addPropertyArray("scaleY", [1.000000]);
__motion_sq_2.addPropertyArray("skewX", [0]);
__motion_sq_2.addPropertyArray("skewY", [0]);
__motion_sq_2.addPropertyArray("rotationConcat", [0]);
__motion_sq_2.addPropertyArray("blendMode", ["normal"]);
// Create an AnimatorFactory instance, which will manage
// targets for its corresponding Motion.
var __animFactory_sq_2:AnimatorFactory = new AnimatorFactory(__motion_sq_2);
__animFactory_sq_2.transformationPoint = new Point(0.499281, 0.499281);
// Call the addTarget function on the AnimatorFactory
// instance to target a DisplayObject with this Motion.
// The second parameter is the number of times the animation
// will play - the default value of 0 means it will loop.
// __animFactory_sq_2.addTarget(<instance name goes here>, 0);
}
<instance name goes here> text.Tip: For dynamic processing of animations, explore using the Timeline object in Flash JavaScript (JSFL) for possibilities in author-time automation. Please see Extending Adobe Flash CS4 Professional in the online Help pages.
The 9-slice scaling feature was introduced in Macromedia Flash 8 and now features an improved, more accurate authortime preview in Adobe Flash CS4. This feature allows you to better control the effects of scaling vector graphics within movie clip instances. By using 9-slice scaling you can create graphics that can be scaled without the distortion that often occur in scaling. For example, you may find this feature very useful when creating button graphics with rounded corners where the graphic needs to change size while retaining the shape of the original button.
Return to the Stage to view the instance again. Scale it to a larger size using the Free Transform tool. Notice that the circles in the corners do not scale and that the stroke weight remains the same.

Figure 8. Guides available for placement while editing within a symbol with 9-slice scaling enabled
To learn more and explore what you can do with graphic effects in Flash CS4, check out the Graphic effects section of the Flash Developer Center.
This content was authored by Adobe Systems, Inc.