Transform from one mc to another mc

Source: Internet
Author: User

Purpose:

There is a form mc1 and a small button mc2. When mc2 is clicked, mc1 will gradually scale to mc2.

 

1. Create two components, mc1 and mc2, on the stage (the best size and location are slightly different)

 

2. Add the following code to the Code layer:

Import flash. display. Sprite;
Import fl. transitions. Tween;
Import fl. transitions. easing. Elastic;
Import fl. transitions. TweenEvent;
Import fl. transitions. easing .*;

Var flag: Boolean = false; // whether the image has been scaled

Mc2.addEventListener (MouseEvent. CLICK, bh );

Var tw0: Tween;
Var tw1: Tween;
Var tw2: Tween;
VaR tw3: tween;

Function BH (e ){
If (FLAG ){
// Restore
Mc1.visible = true;
Tw0.yoyo ();
Tw1.yoyo ();
Tw2.yoyo ();
Tw3.yoyo ();
} Else {
VaR SCX: Number = mc2.width/mc1.width; // final value of scalex axis Scaling
VaR SCY: Number = mc2.height/mc1.height; // final value of scaley axis Scaling

Tw0 = new tween (mc1, "X", regular. easeout, mc1.x, mc2.x, 3, true); // it takes 3 seconds, and the following is the same
Tw1 = new tween (mc1, "Y", regular. easeout, mc1.y, mc2.y, 3, true );
TW2 = new tween (mc1, "scalex", regular. easeout, 1, SCX, 3, true );
Tw3 = new tween (mc1, "scaley", regular. easeout, 1, SCY, 3, true );
Tw3.addeventlistener (tweenevent. motion_finish, mfinish); // hide mc1 after scaling.
}
Flag =! Flag;
}
Function mfinish (E: tweenevent ){
If (FLAG ){
Mc1.visible = false;
}
}

 

3. Run Ctrl + enter

 

 

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.