EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Working with Filters Using Actionscript

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Working with filters using ActionScript 505
Working with filters using ActionScript
The flash.filters package contains classes for the bitmap filter effects that are new in Flash
Player 8. Filters let you use ActionScript to apply rich visual effects, such as blur, bevel, glow,
and drop shadow, to text, movie clip, and button instances. You can also use the Flash
authoring tool to apply filter effects to objects such as text, images, and video. Flash has nine
filter effects, although only seven are accessible by using the user interface in Flash
Professional 8. The ConvolutionFilter and DisplacementMapFilter filters are only available by
using ActionScript code.
The following procedure loads a semitransparent PNG image, and applies a GlowFilter effect
to the nontransparent portion of the image.
To apply filters to semitransparent images:
1. Create a new Flash document and save it as transparentImg.fla.
2. Add the following ActionScript to Frame 1 of the Timeline:
import flash.filters.GlowFilter;
System.security.allowDomain("http://www.helpexamples.com");
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc._x = (Stage.width - target_mc._width) / 2;
target_mc._y = (Stage.height - target_mc._height) / 2;
var glow:GlowFilter = new GlowFilter();
target_mc.filters = [glow];
};
this.createEmptyMovieClip("img_mc", 10);
var img_mcl:MovieClipLoader = new MovieClipLoader();
img_mcl.addListener(mclListener);
img_mcl.loadClip("http://www.helpexamples.com/flash/images/logo.png",
img_mc);
This code uses a movie clip loader instance to load a semi-transparent PNG image. After
the image finishes loading, the image moves to the center of the Stage and a glow filter
is applied.
3. Select Control > Test Movie to test the document.
The glow filter effect is only applied to the opaque (nontransparent) area of the
PNG image.
NOTE
All filters are availabe by using ActionScript in both Flash Basic 8 and Flash Professional
8.

Table of Contents

Related product manuals