Packageflash.filters
Classpublic final class DisplacementMapFilter
InheritanceDisplacementMapFilter Inheritance BitmapFilter Inheritance Object

The DisplacementMapFilter class uses the pixel values from the specified BitmapData object (called the displacement map image) to perform a displacement of an object. You can use this filter to apply a warped or mottled effect to any object that inherits from the DisplayObject class, such as MovieClip, SimpleButton, TextField, and Video objects, as well as to BitmapData objects.

The use of filters depends on the object to which you apply the filter:

If you apply a filter to a display object, the value of the cacheAsBitmap property of the display object is set to true. If you clear all filters, the original value of cacheAsBitmap is restored.

The filter uses the following formula:

dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) * scaleX) / 256, y + ((componentY(x, y) - 128) *scaleY) / 256)

where componentX(x, y) gets the componentX property color value from the mapBitmap property at (x - mapPoint.x ,y - mapPoint.y).

The map image used by the filter is scaled to match the Stage scaling. It is not scaled when the object itself is scaled.

This filter supports Stage scaling. However, general scaling, rotation, and skewing are not supported. If the object itself is scaled (if the scaleX and scaleY properties are set to a value other than 1.0), the filter effect is not scaled. It is scaled only when the user zooms in on the Stage.

View the examples.

See also
flash.display.BitmapData.applyFilter(), flash.display.DisplayObject.filters, flash.display.DisplayObject.cacheAsBitmap


Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties
 PropertyDefined by
  alpha : Number
Specifies the alpha transparency value to use for out-of-bounds displacements.
DisplacementMapFilter
  color : uint
Specifies what color to use for out-of-bounds displacements.
DisplacementMapFilter
  componentX : uint
Describes which color channel to use in the map image to displace the x result.
DisplacementMapFilter
  componentY : uint
Describes which color channel to use in the map image to displace the y result.
DisplacementMapFilter
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  mapBitmap : BitmapData
A BitmapData object containing the displacement map data.
DisplacementMapFilter
  mapPoint : Point
A flash.geom.Point value that contains the offset of the upper-left corner of the target movie clip from the upper-left corner of the map image.
DisplacementMapFilter
  mode : String
The mode for the filter.
DisplacementMapFilter
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  scaleX : Number
The multiplier to use to scale the x displacement result from the map calculation.
DisplacementMapFilter
  scaleY : Number
The multiplier to use to scale the y displacement result from the map calculation.
DisplacementMapFilter
Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods
 FunctionDefined by
  
DisplacementMapFilter(mapBitmap:BitmapData = null, mapPoint:Point = null, componentX:uint = 0, componentY:uint = 0, scaleX:Number = 0.0, scaleY:Number = 0.0, mode:String = "wrap", color:uint = 0, alpha:Number = 0.0)
Initializes a DisplacementMapFilter instance with the specified parameters.
DisplacementMapFilter
  
Returns a copy of this filter object.
DisplacementMapFilter
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property detail
alpha property
alpha:Number  [read-write]

Specifies the alpha transparency value to use for out-of-bounds displacements. It is specified as a normalized value from 0.0 to 1.0. For example, .25 sets a transparency value of 25%. The default is 0. Use this property if the mode property is set to DisplacementMapFilterMode.COLOR.

Implementation
    public function get alpha():Number
    public function set alpha(value:Number):void
color property
color:uint  [read-write]

Specifies what color to use for out-of-bounds displacements. The valid range of displacements is 0.0 to 1.0. Values are in hexadecimal format. The default value for color is 0. Use this property if the mode property is set to DisplacementMapFilterMode.COLOR.

Implementation
    public function get color():uint
    public function set color(value:uint):void
componentX property
componentX:uint  [read-write]

Describes which color channel to use in the map image to displace the x result. Possible values are BitmapDataChannel constants:

Implementation
    public function get componentX():uint
    public function set componentX(value:uint):void

See also
flash.display.BitmapDataChannel
componentY property
componentY:uint  [read-write]

Describes which color channel to use in the map image to displace the y result. Possible values are BitmapDataChannel constants:

Implementation
    public function get componentY():uint
    public function set componentY(value:uint):void

See also
flash.display.BitmapDataChannel
mapBitmap property
mapBitmap:BitmapData  [read-write]

A BitmapData object containing the displacement map data.

Implementation
    public function get mapBitmap():BitmapData
    public function set mapBitmap(value:BitmapData):void

See also
flash.display.BitmapData
mapPoint property
mapPoint:Point  [read-write]

A flash.geom.Point value that contains the offset of the upper-left corner of the target movie clip from the upper-left corner of the map image.

Implementation
    public function get mapPoint():Point
    public function set mapPoint(value:Point):void

See also
flash.geom.Point
mode property
mode:String  [read-write]

The mode for the filter. Possible values are DisplacementMapFilterMode constants:

Implementation
    public function get mode():String
    public function set mode(value:String):void

See also
flash.filters.DisplacementMapFilterMode
scaleX property
scaleX:Number  [read-write]

The multiplier to use to scale the x displacement result from the map calculation.

Implementation
    public function get scaleX():Number
    public function set scaleX(value:Number):void
scaleY property
scaleY:Number  [read-write]

The multiplier to use to scale the y displacement result from the map calculation.

Implementation
    public function get scaleY():Number
    public function set scaleY(value:Number):void
Constructor detail
DisplacementMapFilter constructor

public function DisplacementMapFilter(mapBitmap:BitmapData = null, mapPoint:Point = null, componentX:uint = 0, componentY:uint = 0, scaleX:Number = 0.0, scaleY:Number = 0.0, mode:String = "wrap", color:uint = 0, alpha:Number = 0.0)

Initializes a DisplacementMapFilter instance with the specified parameters.

Parameters
mapBitmap:BitmapData (default = null) — A BitmapData object containing the displacement map data.
mapPoint:Point (default = null) — A flash.geom.Point value that contains the offset of the upper-left corner of the target movie clip from the upper-left corner of the map image.
componentX:uint (default = 0) — Describes which color channel to use in the map image to displace the x result. Possible values are the BitmapDataChannel constants.
componentY:uint (default = 0) — Describes which color channel to use in the map image to displace the y result. Possible values are the BitmapDataChannel constants.
scaleX:Number (default = 0.0) — The multiplier to use to scale the x displacement result from the map calculation.
scaleY:Number (default = 0.0) — The multiplier to use to scale the y displacement result from the map calculation.
mode:String (default = "wrap") — The mode of the filter. Possible values are the DisplacementMapFilterMode constants.
color:uint (default = 0) — Specifies the color to use for out-of-bounds displacements. The valid range of displacements is 0.0 to 1.0. Use this parameter if mode is set to DisplacementMapFilterMode.COLOR.
alpha:Number (default = 0.0) — Specifies what alpha value to use for out-of-bounds displacements. It is specified as a normalized value from 0.0 to 1.0. For example, .25 sets a transparency value of 25%. The default is 1.0. Use this parameter if mode is set to DisplacementMapFilterMode.COLOR.

See also
flash.display.BitmapDataChannel, flash.filters.DisplacementMapFilterMode
Method detail
clone method

public override function clone():BitmapFilter

Returns a copy of this filter object.

Returns
BitmapFilter — A new DisplacementMapFilter instance with all the same properties as the original one.
Class examples

The following example draws a square with a radial gradient fill, creates a text field, creates a BitmapData object, and applies a displacement map filter to the DisplacementMapFilterExample object. Highlights of the example follow:
  1. The class defines variables for the background color, for the text field label, and for the size and offset that will be used in various functions.
  2. The constructor function calls the draw() method, which uses the methods of the Graphics class to draw a square with a radial gradient fill. Note that graphics is a property of the DisplacementMapFilterExample object, which extends Sprite.
  3. The constructor function calls the createLabel() method, which creates a text field displaying the value of labelText and adds it to the display list.
  4. The constructor function calls the createFilter() method, which does the following:
    • Creates a variable named filter for the filter object.
    • Calls the getDisplacementMapFilter() method and assigns its return value to the filter variable.
    • Passes filter to the filters property of the DisplacementFilterExample object (the main class).
  5. The getBitmapFilter() method creates a BitmapData object named mapBitmap and assigns it the results of the createBitmapData() method. The mapBitmap object, along with other variables, defines a new displacement map filter.
  6. The createBitmapData() method creates a new BitmapData object that is based on the current contents of the DisplacementMapFilterExample object. It creates a new bitmap based on bitmapData and adds the bitmap to the Stage.
package {
    import flash.display.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.text.TextField;
    
    public class DisplacementMapFilterExample extends Sprite {
        private var bgColor:uint      = 0xFFCC00;
        private var size:uint          = 200;
        private var offset:uint       = 90;
        private var labelText:String = "Watch the text bend with the displacement map";

        public function DisplacementMapFilterExample() {
            draw();
            createLabel();
            createFilter();
        }

        private function createFilter():void {
            var filter:BitmapFilter = getBitmapFilter();
            filters = new Array(filter);
        }

        private function getBitmapFilter():BitmapFilter {
            var mapBitmap:BitmapData = createBitmapData();
            var mapPoint:Point          = new Point(0, 0);
            var channels:uint          = BitmapDataChannel.RED;
            var componentX:uint      = channels;
            var componentY:uint      = channels;
            var scaleX:Number          = .5;
            var scaleY:Number          = -30;
            var mode:String          = DisplacementMapFilterMode.CLAMP;
            var color:uint              = 0;
            var alpha:Number          = 0;
            return new DisplacementMapFilter(mapBitmap,
                                             mapPoint,
                                             componentX,
                                             componentY,
                                             scaleX,
                                             scaleY,
                                             mode,
                                             color,
                                             alpha);
        }

        private function draw():void {
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(size, size);
            graphics.beginGradientFill(GradientType.RADIAL,
                                       [0xFF0000, 0x0000FF],
                                       [100, 100],
                                       [55, 200],
                                       matrix,
                                       SpreadMethod.PAD);
            graphics.drawRect(0, 0, size, size);
        }

        private function createBitmapData():BitmapData {
            var bitmapData:BitmapData = new BitmapData(size, size, true, bgColor);
            bitmapData.draw(this, new Matrix());
            var bitmap:Bitmap = new Bitmap(bitmapData);
            bitmap.x = size;
            addChild(bitmap);
            return bitmapData;
        }

        private function createLabel():void {
            var label:TextField = new TextField();
            label.text = labelText;
            label.y = offset;
            label.width = size;
            addChild(label);
        }
    }
}




 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/labs/flashauthoringpreview/flash/filters/DisplacementMapFilter.html