back、9(注冊點置中、尺寸一致)。Card(類名同),兩幀分別放置正反面。Main 控制 Card 實例的 rotationY 實現 3D 翻轉。







package {
import flash.display.*;
import flash.events.*;
import caurina.transitions.Tweener; // 第三方緩動庫
public class Main extends Sprite {
private var container:Sprite;
private var pane:MovieClip;
private var isback:Boolean = true;
private var currentPlane:MovieClip;
private var currentRotationY:Number;
public function Main():void {
// 容器置中
container = new Sprite();
container.x = stage.stageWidth/2;
container.y = stage.stageHeight/2;
addChild(container);
// 實例化 Card 並配置
pane = new Card();
container.addChild(pane);
pane.stop(); // 停在第 1 幀(背面)
pane.buttonMode = true; // 手型游標
pane.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void {
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
currentPlane = MovieClip(e.currentTarget);
if (isback) {
Tweener.addTween(currentPlane, { rotationY: 0, time: 1 });
} else {
Tweener.addTween(currentPlane, { rotationY: -180, time: 1 });
}
isback = !isback;
}
private function enterFrameHandler(e:Event):void {
currentRotationY = currentPlane.rotationY;
// 旋轉至 -90°~10° 區間時切換正反面幀
if (currentRotationY >= -90 && currentRotationY <= 10) {
currentPlane.gotoAndStop(isback ? 2 : 1);
stage.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
}
}
rotationY 從 0° 到 -180°,配合 Tweener 緩動,視覺上呈現翻面效果。ENTER_FRAME 中判斷 rotationY 進入 -90° 附近時,瞬間 gotoAndStop 切換正反面幀,避免穿模。ENTER_FRAME 監聽,避免效能浪費。z 軸縮放,可實現「翻轉時放大/縮小」的透視增強效果。Card 類名與庫元件連結一致。Tweener 庫(或改用原生 Tween 類)。出處:《Flash CS4 動畫設計與制作 208 例》