ループ(両端) : ActonScript
マウスに応じて水平方向にループするサンプルです。
ライブラリ : 下記画像をシンボルとして作成。リンケージ名Container。

//--------------------------------------------------------------------------
//
// Container
//
//--------------------------------------------------------------------------
function Container(x, y, i)
{
this._x = x;
this._y = y;
var index:Number = i;
var containers:Array = [];
this.initContainer = function(arr)
{
containers = arr;
this.onEnterFrame = moveHandler;
};
var moveHandler = function ()
{
var vx = _root._xmouse - Stage.width / 2;
vx *= 0.2;
if (this._x + this._width < 0 && vx < 0)
{
switch (index)
{
case 0 :
trace(vx);
this._x = containers[1]._x + this._width-vx;
this._x += vx;
break;
case 1 :
this._x = containers[0]._x + this._width;
this._x += vx;
break;
default :
break;
}
}
else if (this._x > Stage.width && vx > 0)
{
switch (index)
{
case 0 :
this._x = containers[1]._x - this._width-vx;
this._x += vx;
break;
case 1 :
this._x = containers[0]._x - this._width;
this._x += vx;
break;
default :
break;
}
}
else
{
this._x += vx;
}
};
}
//--------------------------------------------------------------------------
//
// Loop
//
//--------------------------------------------------------------------------
function Loop()
{
var containers = [];
this.initLoop = function()
{
containers[0] = _root.attachMovie("Container", "container0", _root.getNextHighestDepth(), new Container(-50, 25, 0));
containers[1] = _root.attachMovie("Container", "container1", _root.getNextHighestDepth(), new Container(-450, 25, 1));
containers[0].initContainer(containers);
containers[1].initContainer(containers);
border.swapDepths(_root.getNextHighestDepth());
};
}
//--------------------------------------------------------------------------
//
// main処理
//
//--------------------------------------------------------------------------
var o = new Loop();
o.initLoop();
スポンサード リンク
この記事にはまだコメントがついていません。
コメントの投稿
段落や改行は自動挿入です。メールアドレスはサイト上では非表示です。
使用できる HTML タグ: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

