Add animation effects to dynamic masks in flash as

Source: Internet
Author: User
Tags event listener


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.