Flash CS4 Resources
Loading or embedding a shader
The first step in using a Pixel Bender shader in ActionScript is to get access to the shader in your ActionScript code. Because a shader is created using the Adobe Pixel Bender Toolkit, and written in the Pixel Bender language, it cannot be directly accessed in ActionScript. Instead, you create an instance of the Shader class that represents the Pixel Bender shader to ActionScript. The Shader object allows you to find out information about the shader, such as whether it expects parameters or input image values. You pass the Shader object to other objects to actually use the shader. For example, to use the shader as a filter you assign the Shader object to a ShaderFilter object’s shader property. Alternatively, to use the shader as a drawing fill, you pass the Shader object as an argument to the Graphics.beginShaderFill() method.
Your ActionScript code can access a shader created by Adobe Pixel Bender Toolkit (a .pbj file) in two ways:
In either case, you link the raw shader bytecode (the URLLoader.data property or an instance of the [Embed] data class) to the Shader instance. As the previous examples demonstrate, you can assign the bytecode to the Shader instance in two ways. You can pass the shader bytecode as an argument to the Shader() constructor. Alternatively, you can set it as the Shader instance's byteCode property.
Once a Pixel Bender shader has been created and linked to a Shader object, you can use the shader to create effects in several ways. You can use it as a filter, a blend mode, a bitmap fill, or for stand-alone processing of bitmap or other data. You can also use the Shader object’s data property to access the shader’s metadata, specify input images, and set parameter values.