Create a new Flash document and save it as a dropshadowmouse.fla.
Add the following ActionScript to frame 1th of the timeline:
The code is as follows |
Copy Code |
Import Flash.filters.DropShadowFilter; System.security.allowDomain ("Http://www.111cn.net"); var dropshadow:dropshadowfilter = new Dropshadowfilter (4, 0x000000, 0.8, 10, 10, 2, 2); Loads the image and locates the image on the stage. var mcllistener:object = new Object (); Mcllistener.onloadinit = function (target_mc:movieclip): Void { target_mc._x = (stage.width-target_mc._width)/2; Target_mc._y = (stage.height-target_mc._height)/2; }; This.createemptymovieclip ("IMG_MC", 10); var img_mcl:moviecliploader = new Moviecliploader (); Img_mcl.addlistener (Mcllistener); Img_mcl.loadclip ("Image1.jpg", IMG_MC); Recalculates the position of the projection when the mouse is moved. var mouselistener:object = new Object (); Mouselistener.onmousemove = function (): Void { var p1:number = img_mc._y-_ymouse; var p2:number = img_mc._x-_xmouse; var degrees:number = math.atan2 (P1, p2)/(math.pi/180); Dropshadow.distance = Math.sqrt (Math.pow (P1, 2) + Math.pow (P2, 2)) * 0.5; Dropshadow.blurx = dropshadow.distance; Dropshadow.blury = Dropshadow.blurx; Dropshadow.angle = degrees-180; Img_mc.filters = [DropShadow]; }; Mouse.addlistener (MouseListener); |
The first part of this code defines the projection instance, loads the external image, and reposition the image in the center of the stage. The second part of the code defines the mouse listener, which is invoked each time the user moves the mouse pointer along the stage. Each time you move the mouse, the event handler recalculates the distance and angle between the mouse pointer and the upper-left corner of the image. Based on this calculation, the drop shadow filter is applied again to the movie clip.