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