DisplacementMapFilter constructor

public DisplacementMapFilter(mapBitmap:BitmapData, mapPoint:Point, componentX:Number, componentY:Number, scaleX:Number, scaleY:Number, [mode:String], [color:Number], [alpha:Number])

Initializes a DisplacementMapFilter instance with the specified parameters.

Availability: ActionScript 1.0; Flash Player 8

Parameters

mapBitmap:BitmapData - A BitmapData object containing the displacement map data.

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.

componentX:Number - Describes which color channel to use in the map image to displace the x result. Possible values are the following:

componentY:Number - Describes which color channel to use in the map image to displace the y result. Possible values are the following:

scaleX:Number - The multiplier to use to scale the x displacement result from the map calculation.

scaleY:Number - The multiplier to use to scale the y displacement result from the map calculation.

mode:String [optional] - The mode of the filter. Possible values are the following:

color:Number [optional] - 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 "color".

alpha:Number [optional] - Specifies what alpha value to use for out-of-bounds displacements. This 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 parameter if mode is set to "color".

Example

The following constructor function creates a new instance of the filter:

myFilter = new flash.filters.DisplacementMapFilter (mapBitmap, mapPoint, componentX, componentY, scale, [mode], [color], [alpha])

The following example instantiates a new DisplacementMapFilter with a radial gradient bitmap and applies it to the text containing MovieClip object txtBlock.

import flash.filters.DisplacementMapFilter;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.geom.ColorTransform;

var mapBitmap:BitmapData = createGradientBitmap(300, 80, 0xFF000000, "radial");

var mapPoint:Point = new Point(-30, -30);
var componentX:Number = 1;
var componentY:Number = 1;
var scaleX:Number = 10;
var scaleY:Number = 10;
var mode:String = "wrap";
var color:Number = 0x000000;
var alpha:Number = 0x000000;

var filter:DisplacementMapFilter = new DisplacementMapFilter(mapBitmap, mapPoint, componentX, componentY, scaleX, scaleY, mode, color, alpha);

var txtBlock:MovieClip = createTextBlock();
txtBlock._x = 30;
txtBlock._y = 30;

txtBlock.filters = new Array(filter);

function createGradientBitmap(w:Number, h:Number, bgColor:Number, type:String, hide:Boolean):BitmapData {
    var mc:MovieClip = this.createEmptyMovieClip("mc", 1);
    var matrix:Matrix = new Matrix();
    matrix.createGradientBox(w, h, 0, 0, 0);

    mc.beginGradientFill(type, [0xFF0000, 0x0000FF], [100, 100], [0x55, 0x99], matrix, "pad"); 
    mc.lineTo(w, 0);
    mc.lineTo(w, h);
    mc.lineTo(0, h);
    mc.lineTo(0, 0);
    mc.endFill();
    (hide == true) ? mc._alpha = 0 : mc._alpha = 100;
    
    var bmp:BitmapData = new BitmapData(w, h, true, bgColor);
        bmp.draw(mc, new Matrix(), new ColorTransform(), "normal", bmp.rectangle, true);
    mc.attachBitmap(bmp, this.getNextHighestDepth());
    
    return bmp;
}

function createTextBlock():MovieClip {
    var txtBlock:MovieClip = this.createEmptyMovieClip("txtBlock", this.getNextHighestDepth());
        txtBlock.createTextField("txt", this.getNextHighestDepth(), 0, 0, 300, 80);
    txtBlock.txt.text = "watch the text bend with the displacement map";
    return txtBlock;
}