13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Filtering display objects<br />

The code first g<strong>en</strong>erates two gradi<strong>en</strong>t circles, which are combined together to form the displacem<strong>en</strong>t map image. The<br />

red circle creates the x axis displacem<strong>en</strong>t (xyFilter.compon<strong>en</strong>tX = BitmapDataChannel.RED), and the blue circle<br />

creates the y axis displacem<strong>en</strong>t (xyFilter.compon<strong>en</strong>tY = BitmapDataChannel.BLUE). To help you understand<br />

what the displacem<strong>en</strong>t map image looks like, the code adds the original circles as well as the combined circle that serves<br />

as the map image to the bottom of the scre<strong>en</strong>.<br />

The code th<strong>en</strong> loads an image and, as the mouse moves, applies the displacem<strong>en</strong>t filter to the portion of the image that’s<br />

under the mouse. The gradi<strong>en</strong>t circles used as the displacem<strong>en</strong>t map image causes the displaced region to spread out<br />

away from the pointer. Notice that the gray regions of the displacem<strong>en</strong>t map image don’t cause any displacem<strong>en</strong>t. The<br />

gray color is 0x7F7F7F. The blue and red channels of that shade of gray exactly match the middle shade of those color<br />

channels, so there is no displacem<strong>en</strong>t in a gray area of the map image. Likewise, in the c<strong>en</strong>ter of the circle there is no<br />

displacem<strong>en</strong>t. Although the color there isn’t gray, that color’s blue channel and red channel are id<strong>en</strong>tical to the blue<br />

channel and red channel of medium gray, and since blue and red are the colors that cause displacem<strong>en</strong>t, no<br />

displacem<strong>en</strong>t happ<strong>en</strong>s there.<br />

Shader filter<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

The ShaderFilter class lets you use a custom filter effect defined as a Pixel B<strong>en</strong>der shader. Because the filter effect is<br />

writt<strong>en</strong> as a Pixel B<strong>en</strong>der shader, the effect can be completely customized. The filtered cont<strong>en</strong>t is passed in to the shader<br />

as an image input, and the result of the shader operation becomes the filter result.<br />

Note: The Shader filter is available in ActionScript starting with Flash Player 10 and Adobe AIR 1.5.<br />

To apply a shader filter to an object, you first create a Shader instance repres<strong>en</strong>ting the Pixel B<strong>en</strong>der shader that you<br />

are using. For details on the procedure for creating a Shader instance and on how to specify input image and parameter<br />

values, see “Working with Pixel B<strong>en</strong>der shaders” on page 300.<br />

Wh<strong>en</strong> using a shader as a filter, there are three important things to keep in mind:<br />

The shader must be defined to accept at least one input image.<br />

The filtered object (the display object or BitmapData object to which the filter is applied) is passed to the shader as<br />

the first input image value. Because of this, do not manually specify a value for the first image input.<br />

Last updated 6/6/2012<br />

291

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!