New Flash 8 instance teaching material: filter effect changed with the mouse
This example uses Flash 8 for production and release. Please update your ie browser plug-in to Flash 8 for viewing ~
[Upload = swf] UploadFile/2005-12/20051231183349122. sw
The following methods are used to create an ECS instance:
1. Create a MC, drag it to the stage, and change the instance name to myMC.
2. Add the following code:
Import flash. filters. *; // load filter class
// Defines the offset distance of the initial oblique filter.
Var maxbeveldistance: Number = 5;
// Create an angle filter.
Var bevel: BevelFilter = new BevelFilter ();
// Defines the intensity of the initial oblique filter.
Bevel. strength =. 6;
// Create a projection filter.
Var dropshadowropShadowFilter = new DropShadowFilter ();
// Initialize the projection filter.
Dropshadow. color = 0x000000;
Dropshadow. alpha =. 75;
Dropshadow. blurX = 10;
Dropshadow. blurY = 10;
// Update filter data following mouse changes
OnMouseMove = function (){
// Calculate the distance between the current mouse and mc
Var dx = _ xmouse-myMC. _ x;
Var dy = _ ymouse-myMC. _ y;
// Calculate the distance
Var distance = Math. sqrt (dx * dx + dy * dy );
// Calculate the offset
Var angle = Math. atan2 (dy, dx );
// Apply the offset distance and angle of oblique light.
Bevel. distance = Math. min (maxbeveldistance, distance/50 );
Bevel. angle = 180 + angle * 180/Math. PI; // convert and rotate 180 degress
// Apply the projection offset distance and angle
Dropshadow. distance = distance/20;
Dropshadow. angle = 180 + angle * 180/Math. PI; // convert and rotate 180 degress
// Add a filter to mc ~
MyMC. filters = [bevel, dropshadow];
}
// Initialization
OnMouseMove ();
Because there are many filters, you can only use these filters or use different filters ~