Create a new Flash document and save it as a dynmask.fla.
Add the following ActionScript to frame 1th of the timeline:
The code is as follows |
Copy Code |
Import Mx.transitions.Tween; Import mx.transitions.easing.*; var mcllistener:object = new Object (); Mcllistener.onloadinit = function (target_mc:movieclip) { Target_mc._visible = false; Center the image on the stage. target_mc._x = (stage.width-target_mc._width)/2; Target_mc._y = (stage.height-target_mc._height)/2; var maskclip:movieclip = Target_mc.createemptymovieclip ("MASK_MC", 20); With (Maskclip) { Draws a mask that is the same size as the loaded image. Beginfill (0XFF00FF, 100); MoveTo (0, 0); LineTo (target_mc._width, 0); LineTo (Target_mc._width, target_mc._height); LineTo (0, target_mc._height); LineTo (0, 0); Endfill (); } Target_mc.setmask (Maskclip); Target_mc._visible = true; var mask_tween:tween = new Tween (Maskclip, "_yscale", Strong.easeout, 0, 2, true); }; This.createemptymovieclip ("IMG_MC", 10); var img_mcl:moviecliploader = new Moviecliploader (); Img_mcl.addlistener (Mcllistener); Img_mcl.loadclip ("/images/image1.jpg", IMG_MC); |
This code example imports each class in the Tween class and the easing package. It then creates an object that is the listener object for the Moviecliploader instance, which is created in the code in the later section. The Listener object defines an event listener onloadinit that causes the dynamically loaded JPEG image to be centered on the stage. After the code reposition the image, a new movie clip instance is created in the TARGET_MC movie clip, which contains the dynamically loaded JPEG image. The drawing API code draws a rectangle with the same size as the JPEG image in this new movie clip. A new movie clip masks a JPEG image by calling the Movieclip.setmask () method. After you draw and set the mask, the mask uses the Tween class to add animation effects, which slowly exposes the image.
Save the Flash document and choose Control > Test Movie to test the SWF file.