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

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

後ろのかえる君と前のかえる君が交代して、位置が入れ替わるの。 :cake:
正確には、入れ替わってはいないけど、そんな感じのイメージ。

This movie requires Flash Player 9.0.0

ライブラリに、ムービークリップ(リンケージ識別子: frog, panel) を用意。
frog には、4フレームあるムービークリップ(インスタンス名: base) を配置。
各フレームには、色違いのかえる君が描いてある。
また、空のムービークリップ(インスタンス名: noHit) も配置。
panel には、4フレームあるムービークリップ(インスタンス名: txt) を配置。
また、ムービークリップ(インスタンス名: closeBtn) も配置。

_root 第1フレームに
var frogMax:Number = 4;
var baseScale:Number = 80;
var backScale:Number = 50;
var basePos:Array = new Array();
var backPos:Array = new Array();
for (var n:Number = 1; n <= frogMax; n++) {
  basePos.push({x: 90+140*(n-1), y: 140});
  backPos.push({x: 350+60*(n-1), y: 60});
}
var frontScale:Number = 120;
var frontPos:Object = {x: 140, y: 140};
var overScale:Number = 100;

var deceleration:Number = 0.25;

for (var n:Number = 1; n <= frogMax; n++) {
  var _mc:MovieClip = this.attachMovie("frog", "frog"+n, n);
  _mc.base.gotoAndStop(n);
  _mc.frogID = n;
  _mc.motion = "base";
  _mc.pos = "base";

  _mc.xPos = {base: basePos[n-1].x, back: backPos[n-1].x, front: frontPos.x};
  _mc.yPos = {base: basePos[n-1].y, back: backPos[n-1].y, front: frontPos.y};
  _mc.scale = overScale;
  _mc._x = _mc.xPos.base;
  _mc._y = _mc.yPos.base;
  _mc._xscale = _mc._yscale = _mc.scale;
  _mc.hitArea = _mc.base;
  _mc.onRelease = function():Void {
    selectItem(this.frogID);
  };
  _mc.onRollOver = function():Void {
    if (this.motion == "base") {
      zoom(this, overScale);
    }
  };
  _mc.onRollOut = function():Void {
    if (this.motion == "base") {
      zoom(this, baseScale);
    }
  };
}
this.attachMovie("panel", "panel", frogMax+1, {_x: 260, _y: 105, _visible: false, _alpha: 0});
panel.txt._visible = false;
panel.txt._alpha = 0;

init();
panel.closeBtn.onRelease = function():Void {
  reset();
  hidePanel();
};

function init():Void {
  for (var n:Number = 1; n <= frogMax; n++) {
    var _mc:MovieClip = this["frog"+n];
    zoom(_mc, baseScale);
  }
}
function reset():Void {
  for (var n:Number = 1; n <= frogMax; n++) {
    var _mc:MovieClip = this["frog"+n];
    moveToTarget(_mc, "base");
  }
}
function selectItem(frogID:Number):Void {
  for (var n:Number = 1; n <= frogMax; n++) {
    var _mc:MovieClip = this["frog"+n];
    if (n == frogID) {
      moveToTarget(_mc, "front");
      showPanel(n);
    } else {
      moveToTarget(_mc, "back");
    }
  }
}
function zoom(_mc:MovieClip, targetScale:Number):Void {
  _mc.onEnterFrame = function():Void {
    this.scale += (targetScale - this.scale)*deceleration;
    this._xscale = this._yscale = this.scale;
    if (Math.abs(targetScale - this.scale) < 0.5) {
      this._xscale = this._yscale = targetScale;
      delete this.onEnterFrame;
    }
  };
}
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;
  _mc.onEnterFrame = function():Void {
    this._x += (xTargetPos - this._x)*deceleration;
    this._y += (yTargetPos - this._y)*deceleration;
    this.scale += (targetScale - this.scale)*deceleration;
    this._xscale = this._yscale = this.scale;
    if (Math.abs(xTargetPos - this._x) < 0.5 && Math.abs(yTargetPos - this._y) < 0.5) {
      this._x = xTargetPos;
      this._y = yTargetPos;
      this._xscale = this._yscale = targetScale;
      this.pos = this.motion;
      if (this.pos != "front") {
        this.hitArea = this.base;
      }
      delete this.onEnterFrame;
    }
  };
}
function showPanel(frogID:Number):Void {
  panel._visible = true;
  panel.txt._alpha = 0;
  panel.txt._visible = true;
  panel.txt.gotoAndStop(frogID);
  panel.onEnterFrame = function():Void {
    this._alpha += 10;
    if (this._alpha >= 100) {
      this._alpha = 100;
      this.txt._alpha += 20;
      if (this.txt._alpha >= 100) {
        this.txt._alpha = 100;
        this.closeBtn.enabled = true;
        delete this.onEnterFrame;
      }
    }
  };
}
function hidePanel():Void {
  panel.closeBtn.enabled = false;
  panel.txt._alpha = 0;
  panel.txt._visible = false;
  panel.onEnterFrame = function():Void {
    this._alpha -= 10;
    if (this._alpha <= 0) {
      this._alpha = 0;
      this._visible = false;
      delete this.onEnterFrame;
    }
  };
}
と記述。

:caution: バグがまだ残ってそうな気が。


[修正] (06/10/14 Sat 17:47)
かえる君をクリックしてすぐに、ステージ外にマウスをはずすと、かえる君が移動しないというバグを修正。(フラグ変更のタイミング)