かえる君の交代メニュー (2)

かえる君が交代するメニュー。 :boy:

後ろのかえる君と前のかえる君が交代して、位置が入れ替わるの。 :cake:
Tweenクラスを使ってみたりしちゃったりして。 😉

This movie requires Flash Player 9.0.0

ムービークリップなどの構造は、 :banana: かえる君の交代メニュー (1) 参照。

_root 第1フレームに
import mx.transitions.Tween;
import mx.transitions.easing.*;


  (中略)

//var deceleration:Number = 0.25;

  (中略)

function zoom(_mc:MovieClip, targetScale:Number):Void {
  var easing:Function = Regular.easeOut;
  var startScale:Number = _mc.scale;
  var frames:Number = 10;
  var scaleTween:Tween = new Tween(_mc, "scale", easing, startScale, targetScale, frames, false);
  scaleTween.onMotionChanged = function():Void {
    _mc._xscale = _mc._yscale = _mc.scale;
  };
}
function moveToTarget(_mc:MovieClip, target:String):Void {
  _mc.motion = target;
  var xTargetPos:Number = _mc.xPos[target];
  var yTargetPos:Number = _mc.yPos[target];
  var targetScale:Number = this[target+"Scale"];
  _mc.hitArea = _mc.noHit;
  var easing:Function = Back.easeOut;
  var xStartPos:Number = _mc._x;
  var yStartPos:Number = _mc._y;
  var startScale:Number = _mc.scale;
  var frames:Number = 16;
  var xTween:Tween = new Tween(_mc, "_x", easing, xStartPos, xTargetPos, frames, false);
  var yTween:Tween = new Tween(_mc, "_y", easing, yStartPos, yTargetPos, frames, false);

  xTween.onMotionFinished = function():Void {
    _mc.pos = _mc.motion;
    if (_mc.pos != "front") {
      _mc.hitArea = _mc.base;
    }
  };
  var scaleTween:Tween = new Tween(_mc, "scale", easing, startScale, targetScale, frames, false);
  scaleTween.onMotionChanged = function():Void {
    _mc._xscale = _mc._yscale = _mc.scale;
  };
}
function showPanel(frogID:Number):Void {
  panel._visible = true;
  panel.txt._alpha = 0;
  panel.txt._visible = true;
  panel.txt.gotoAndStop(frogID);
  var easing:Function = None.easeNone;
  var startAlpha:Number = panel._alpha;
  var frames:Number = 10;
  var panelTween:Tween = new Tween(panel, "_alpha", easing, startAlpha, 100, frames, false);
  panelTween.onMotionFinished = function():Void {
    var txtTween:Tween = new Tween(panel.txt, "_alpha", easing, 0, 100, frames*0.5, false);
    txtTween.onMotionFinished = function():Void {
      panel.closeBtn.enabled = true;
    };
  };
}
function hidePanel():Void {
  panel.closeBtn.enabled = false;
  panel.txt._alpha = 0;
  panel.txt._visible = false;
  var easing:Function = None.easeNone;
  var startAlpha:Number = panel._alpha;
  var frames:Number = 10;
  var panelTween:Tween = new Tween(panel, "_alpha", easing, startAlpha, 0, frames, false);
  panelTween.onMotionFinished = function():Void {
    panel._visible = false;
  };
}
と記述。

Tweenクラスを用いることで、スクリプトがもう少しすっきりするかと思ったけれども、それほどスマートでもない気が。 :bouzu:

でも、イージングの種類を簡単に変えられるのは、グー。 :bear: