マウスに応じて水平方向にループするサンプルです。
ライブラリ : 下記画像をシンボルとして作成。リンケージ名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();
No comments yet.
改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。