The DisplacementMapFilter Class


The DisplacementMapFilter Class

The DisplacementMapFilter in conjunction with the BitmapData class creates a mapped displacement with an image.

It is important when using this class to import it first at the beginning of your script, like this:

 import flash.filters.DisplacementMapFilters; 

And to instantiate a new instance of the DisplacementMapFilter class, use this code as a template:

[View full width]

var myFilter:DisplacementMapFilter = new DisplacementMapFilter(bitmap, point, compX, compY , scaleX, scaleY, mode, color, alpha);

  • bitmap The BitmapData object containing the displacement information.

  • point The top-left corner of the bitmap in comparison to the image being displaced.

  • compX The color to use on the horizontal displacement. Values: 1, 2, 4, 8.

  • compY The color to use on the vertical displacement. Values: 1, 2, 4, 8.

  • scaleX The multiplier used to scale the horizontal displacement.

  • scaleY The multiplier used to scale the vertical displacement.

  • mode A string value representing the filter mode that has these possible values:

    • clamp locks the displacement value to the edge of the bitmap.

    • color if the displacement value is beyond the bitmap, color will be used as a substitute.

    • ignore if the displacement is beyond the bitmap, it will be ignored.

    • wrap when the displacement value goes beyond the bitmap, it will be wrapped around.

  • color A substitute color for pixels outside the bitmap. This parameter is only used when mode is set to "color."

  • alpha The alpha value of color. Range is between 0 and 1 with the default being 1. This parameter is used only when mode is set to "color."

Example:

This example already has an image on the stage called img_mc. The code imports all the classes we need. Then it creates a point at (0,0). After that, it creates an instance of the BitmapData object to use as the displacement map. It sets the dimensions to the dimensions of the image. And finally, it creates an event that will constantly update the filter.

[View full width]

import flash.filters.DisplacementMapFilter; import flash.display.BitmapData; import flash.geom.Point; //create a point var pint:Point = new Point(0,0); //create the map displacement bitmap with the images dimensions var myBitmapData:BitmapData = new BitmapData(img_mc._width, img_mc._height); //constantly update this.onEnterFrame = function(){ myBitmapData.noise(Math.random()*20, 1, 200, 1, true); //create the filter var myFilter:DisplacementMapFilter = new DisplacementMapFilter (myBitmapData, point, 1 ,1,10,10,"wrap"); //apply the filter img_mc.filters = new Array(myFilter); }

Because the properties of this object match the parameters identically, they will be skipped.

Methods

clone

Availability: FP:8, AS:1.0

Generic Template: myFilter.clone()

Returns: DisplacementMapFilter

An exact copy of the DisplacementMapFilter will be returned.

Description:

This method will create a duplicate copy of the DisplacementMapFilter it is called on.

Example:

This example will create a filter, clone it, then walk through all the properties to see that they match:

[View full width]

import flash.filters.DisplacementMapFilter; import flash.display.BitmapData; import flash.geom.Point; //create a point var pint:Point = new Point(0,0); //create the map displacement bitmap with the images dimensions var myBitmapData:BitmapData = new BitmapData(100, 100); //create some noise myBitmapData.noise(Math.random()*20, 1, 200, 1, true); //create the filter var myFilter:DisplacementMapFilter = new DisplacementMapFilter (myBitmapData, point, 1,1 ,10,10,"wrap"); //apply the filter img_mc.filters = new Array(myFilter); //create a copy var myNewFilter:DisplacementMapFilter = myFilter.clone(); //walk through and display each property for(each in myNewFilter){ trace(each + ": " + myNewFilter[each]); } //output:clone: [type Function] //alpha: 0 //color: 0 //mode: wrap //scaleY: 10 //scaleX: 10 //componentY: 1 //componentX: 1 //mapPoint: (x=0, y=0) //mapBitmap: [object Object]




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net