Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Animation, Filters, and Drawings > Manipulating filter effects with code > Adjusting filter properties | |||
The array of filters applied to an object can be accessed through standard ActionScript calls by using the MovieClip.filters property. This process returns an array that contains each filter object currently associated with the MovieClip. Each filter has a set of properties unique to that filter. The filters can be accessed and modified just like an array object, although getting and setting the filters by using the filters property returns a duplicate of the filters object instead of a reference.
Setting the filters property duplicates the filters array passed in and does not store it as a reference. When getting the filters property, it returns a new copy of the array. One negative implication of this approach is that the following code does not work:
// does not work my_mc.filters[0].blurX = 20;
Because the previous code snippet returns a copy of the filters array, the code modifies the copy instead of the original array. In order to modify the blurX property, you would need to use the following ActionScript code instead:
// works var filterArray:Array = my_mc.filters; filterArray[0].blurX = 20; my_mc.filters = filterArray;
The following procedure blurs an image based on the current position of the mouse pointer on the Stage. Whenever the mouse pointer moves horizontally or vertically, the blurX and blurY properties of the blur filter are modified accordingly.
import flash.filters.BlurFilter;
this.createEmptyMovieClip("holder_mc", 10);
holder_mc.createEmptyMovieClip("img_mc", 20);
holder_mc.img_mc.loadMovie("http://www.helpexamples.com/flash/images/image2.jpg");
holder_mc.filters = [new BlurFilter(10, 10, 2)];
holder_mc._x = 75;
holder_mc._y = 75;
holder_mc.onMouseMove = function() {
var tempFilter:BlurFilter = holder_mc.filters[0];
tempFilter.blurX = Math.floor((_xmouse / Stage.width) * 255);
tempFilter.blurY = Math.floor((_ymouse / Stage.height) * 255);
holder_mc.filters = [tempFilter];
};
The previous code is split into three sections. The first section imports the flash.filters.BlurFilter class so that you don't have to use the fully qualified class name when you refer to the BlurFilter class. The second section of code creates a couple of movie clips and loads an image into one of the nested clips. The third section of code responds to the mouse movement on the Stage and adjusts the blur accordingly.
Moving the mouse pointer along the x-axis modifies the blur filter's blurX property. Moving the mouse pointer along the y-axis modifies the blur filter's blurY property. The closer the mouse pointer is to the upper-left corner of the Stage, the less blurring is applied to the movie clip.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000987.html