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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Working with Pixel B<strong>en</strong>der shaders<br />

Each ShaderParameter object also has an index property that indicates where the parameter fits in the order of the<br />

shader’s parameters. In addition to these properties, a ShaderParameter object can have additional properties<br />

containing metadata values provided by the shader’s author. For example, the author can specify metadata values such<br />

as minimum, maximum, and default values for a parameter. Any metadata values that the author specifies are added<br />

to the ShaderParameter object as dynamic properties. To examine those properties, use a for..in loop to loop over<br />

the ShaderParameter object’s dynamic properties to id<strong>en</strong>tify its metadata. The following example shows how to use a<br />

for..in loop to id<strong>en</strong>tify a ShaderParameter object’s metadata. Each metadata value is added to a Vector instance<br />

named metadata. Note that this example assumes a Shader instance named myShader is already created, and that it is<br />

known to have a parameter named brightness:<br />

var brightness:ShaderParameter = myShader.data.brightness;<br />

var metadata:Vector. = new Vector.();<br />

for (var prop:String in brightness)<br />

{<br />

if (brightness[prop] is String)<br />

{<br />

metadata[metadata.l<strong>en</strong>gth] = brightness[prop];<br />

}<br />

}<br />

// do something with the metadata<br />

Using a shader<br />

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

Once a Pixel B<strong>en</strong>der shader is available in ActionScript as a Shader object, it can be used in several ways:<br />

Shader drawing fill: The shader defines the fill portion of a shape drawn using the drawing api<br />

Bl<strong>en</strong>d mode: The shader defines the bl<strong>en</strong>d betwe<strong>en</strong> two overlapping display objects<br />

Filter: The shader defines a filter that modifies the appearance of visual cont<strong>en</strong>t<br />

Stand-alone shader processing: The shader processing runs without specifying the int<strong>en</strong>ded use of the output. The<br />

shader can optionally run in the background, with the result is available wh<strong>en</strong> the processing completes. This<br />

technique can be used to g<strong>en</strong>erate bitmap data and also to process non-visual data.<br />

Using a shader as a drawing fill<br />

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

Wh<strong>en</strong> you use a shader to create a drawing fill, you use the drawing api methods to create a vector shape. The shader’s<br />

output is used to fill in the shape, in the same way that any bitmap image can be used as a bitmap fill with the drawing<br />

api. To create a shader fill, at the point in your code at which you want to start drawing the shape, call the Graphics<br />

object’s beginShaderFill() method. Pass the Shader object as the first argum<strong>en</strong>t to the beginShaderFill()<br />

method, as shown in this listing:<br />

var canvas:Sprite = new Sprite();<br />

canvas.graphics.beginShaderFill(myShader);<br />

canvas.graphics.drawRect(10, 10, 150, 150);<br />

canvas.graphics.<strong>en</strong>dFill();<br />

// add canvas to the display list to see the result<br />

Last updated 6/6/2012<br />

310

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

Saved successfully!

Ooh no, something went wrong!