目的:
有一个窗体mc1和一个小按钮mc2, 点击mc2时, mc1会逐渐缩到mc2上.
1.在舞台上建立两个元件mc1,mc2(最好大小和位置区别大一点)
2.在代码层加入以下代码
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;//是否已缩放
mc2.addEventListener(MouseEvent.CLICK, bh);
var tw0:Tween;
var tw1:Tween;
var tw2:Tween;
var tw3:Tween;
function bh(e) {
if (flag) {
//复原
mc1.visible = true;
tw0.yoyo();
tw1.yoyo();
tw2.yoyo();
tw3.yoyo();
} else {
var scx:Number = mc2.width/mc1.width; //scaleX轴缩放的最终值
var scy:Number = mc2.height/mc1.height; //scaleY轴缩放的最终值
tw0 = new Tween(mc1, "x", Regular.easeOut, mc1.x , mc2.x, 3 , true); //用时需要3秒, 以下用时是一样的
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); //在缩放完成后,将mc1隐藏
}
flag = !flag;
}
function mFinish(e:TweenEvent) {
if (flag) {
mc1.visible = false;
}
}
3.Ctrl + Enter运行