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 />

4 Save the Pixel B<strong>en</strong>der bytecode file in the same directory as the Flash docum<strong>en</strong>t. The file’s name should match the<br />

name specified in the example description.<br />

The ActionScript part of each example is writt<strong>en</strong> as a class file. To test the example in Flash Professional:<br />

1 Create an empty Flash docum<strong>en</strong>t and save it to your computer.<br />

2 Create a new ActionScript file and save it in the same directory as the Flash docum<strong>en</strong>t. The file’s name should match<br />

the name of the class in the code listing. For instance, if the code listing defines a class named MyApplication, use<br />

the name MyApplication.as to save the ActionScript file.<br />

3 Copy the code listing into the ActionScript file and save the file.<br />

4 In the Flash docum<strong>en</strong>t, click a blank part of the Stage or work space to activate the docum<strong>en</strong>t Property inspector.<br />

5 In the Property inspector, in the Docum<strong>en</strong>t Class field, <strong>en</strong>ter the name of the ActionScript class you copied from<br />

the text.<br />

6 Run the program using Control > Test Movie<br />

You will see the results of the example in the preview window.<br />

These techniques for testing example code listings are explained in more detail in “How to Use ActionScript Examples”<br />

on page 1085.<br />

Loading or embedding a shader<br />

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

The first step in using a Pixel B<strong>en</strong>der shader in ActionScript is to get access to the shader in your ActionScript code.<br />

Because a shader is created using the Adobe Pixel B<strong>en</strong>der Toolkit, and writt<strong>en</strong> in the Pixel B<strong>en</strong>der language, it cannot<br />

be directly accessed in ActionScript. Instead, you create an instance of the Shader class that repres<strong>en</strong>ts the Pixel B<strong>en</strong>der<br />

shader to ActionScript. The Shader object allows you to find out information about the shader, such as whether it<br />

expects parameters or input image values. You pass the Shader object to other objects to actually use the shader. For<br />

example, to use the shader as a filter you assign the Shader object to a ShaderFilter object’s shader property.<br />

Alternatively, to use the shader as a drawing fill, you pass the Shader object as an argum<strong>en</strong>t to the<br />

Graphics.beginShaderFill() method.<br />

Your ActionScript code can access a shader created by Adobe Pixel B<strong>en</strong>der Toolkit (a .pbj file) in two ways:<br />

Loaded at run time: the shader file can be loaded as an external asset using a URLLoader object. This technique is<br />

like loading an external asset such as a text file. The following example demonstrates loading a shader bytecode file<br />

at run time and linking it to a Shader instance:<br />

Last updated 6/6/2012<br />

302

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

Saved successfully!

Ooh no, something went wrong!