Working with filters using ActionScript
513
You can also apply drop shadows to dynamically loaded semitransparent PNG images. In the
following procedure, the drop shadow filter is applied only to the solid area of the PNG, not
the transparency.
To apply a drop shadow to a semitransparent image:
1.
Create a new Flash document and save it as
dropshadowTransparent.fla
.
2.
Add the following ActionScript to Frame 1 of the Timeline:
import flash.filters.DropShadowFilter;
System.security.allowDomain("http://www.helpexamples.com");
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip):Void {
target_mc._x = (Stage.width - target_mc._width) / 2;
target_mc._y = (Stage.height - target_mc._height) / 2;
var dropShadow:DropShadowFilter = new DropShadowFilter(4, 45,
0x000000, 0.5, 10, 10, 2, 3);
target_mc.filters = [dropShadow];
};
mclListener.onLoadError = function(target_mc:MovieClip):Void {
trace("unable to load image.");
};
this.createEmptyMovieClip("logo_mc", 10);
var my_mcl:MovieClipLoader = new MovieClipLoader();
my_mcl.addListener(mclListener);
my_mcl.loadClip("http://www.helpexamples.com/flash/images/logo.png",
logo_mc);
This ActionScript code uses the MovieClipLoader class to load an image and apply a drop
shadow filter when the image is completely loaded from the remote server.
3.
Select Control > Test Movie to test the Flash document.
Flash loads a PNG image with a transparent background. When you apply the drop
shadow filter, only the opaque (nontransparent) portion of the image has the filter
applied.
Using the glow filter
The GlowFilter class lets you add a glow effect to various objects in Flash. The glow algorithm
is based on the same box filter that is the blur filter uses (see
“Using the blur filter”
on page 507
). You can set the style of the glow in several ways, including inner or outer glow
and knockout mode. The glow filter is similar to the drop shadow filter with the
distance
and
angle
properties of the drop shadow set to
0
.
For more information on the glow filter, see GlowFilter (flash.filters.GlowFilter) in the
ActionScript 2.0 Language Reference
.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...