- フレームの順再生と逆再生
- onEnterFrame
- this.nextFrame()/prevFrame()
- フレームの接触を感知
フレームの順再生と逆再生
this.stop();
function openUmbrella():Void
{
this.onEnterFrame = playForward;
}
function closeUmbrella():Void
{
this.onEnterFrame = playBackward;
}
function playForward():Void
{
this.nextFrame();
if( this._currentframe == this._totalflames )
delete this.onEnterFrame;
}
function playBackward():Void
{
this.prevFrame();
if( this._currentframe == 1 )
delete this.onEnterFrame;
}
- openUmbrella関数が実行されたら、フレームごとに(onEnterFrame)、playForward関数が呼ばれる。
- this.nextFrame();をフレーム毎に呼び出すことで順再生。
- this.prevFrame();をフレーム毎で逆再生。
- if( this.currentframe == this.totalflames )
- 現在のフレーム番号が全体のフレーム数に達したら…
- delete this.onEnterFrame;
- onEnterFrameイベントに割り当てた関数(playForward)を解除。以後playForwardが呼び出されなくなる。
フレームの接触を感知
- 上で作ったムービークリップをシーンに配置
- アニメする人のインスタンス名「human」
- 雨雲のインスタンス名「rainCloud」
- 濡れた地面のインスタンス名「wetGround」
- wetGroundとhumanが接触した時、humanの関数open/closeUmbrellaを実行…
- シーン1にスクリプトを記述…
var human: MovieClip;
human.onMouseMove = moveRainCloud;
function moveRainCloud():Void
{
rainCloud._x = this._parent._xmouse;
wetGround._x = this._parent._xmouse;
if( this.hitTest(wetGround) )
{
this.openUmbrella();
}else
{
this.closeUmbrella();
}
}
- human.onMouseMove▶humanのonMouseMoveイベント(マウスが動くごとに呼ばれるイベント)にmoveRainCloudという関数を割り当て。
- rainCloud.x / wetGround.x▶雨雲、濡れた地面を横方向に移動。
- this.parent.xmouse▶_rootでのマウスポインタのX座標を調べてその位置に合わせる。
- if( this.hitTest(wetGround) )▶this(human)がwetGroundと接触しているか?
- this.openUmbrella()▶this(human)の関数openUmbrellaを実行
- 他のムービークリップと接触しているか調べることができる
- 接触していたらtrue,いなければfalseを返す