Macromedia Flash Professional 8 Unleashed
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
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
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 |
Категории