我有一个有5个孩子mcs的容器mc。
儿童姓名为mc0,mc1 .... mc4。
cont.getChildByName("mc"+Number(cont.numChildren-1)).x = cont.getChildByName("mc0").x - 20 *1.2;
在此重新定位过程之后..我想将最后一个项目位置设置为0,依此类推。我怎么能这样做?
我的目标是实现循环运动。
喜欢
[mc0][mc1][mc2]
[mc2][mc0][mc1]
[mc1][mc2][mc0]
[mc0][mc1][mc2]
答案 0 :(得分:1)
//Of course, you don't necessarily have to create absolute positions,
//this is a simple example...
var positions:Array = [{x:0,y:0} , {x:20, y:20} etc....];
var children:Array = [mc0 , mc1 ... mcN];
//Provided that positions & children have the same length
private function rotate():void
{
//remove the last element of the Array
var lastChild:MovieClip = children.pop();
//Add it to the beginning of the Array
children.unshift(lastChild );
//Assign new positions
//Here you could tween for smoother effect
for( var i:int ; i < positions.length ; ++i )
{
children[i].x = positions[i].x;
children[i].y = positions[i].y;
}
}
答案 1 :(得分:1)
让我们介绍一个模拟旋转进展的偏移变量:
var offset:uint = 0;
现在我们必须根据此变量定义每个剪辑的位置。我将介绍两个项目之间距离的间隙常数。
const GAP:uint = 20;
for (var iMc:int=0; iMc < cont.numChildren; iMc++)
{
mc = cont.getChildByName("mc" + iMc.toString()) as Sprite;
mc.x = GAP * ((iMc + offset) % cont.numChildren);
}
%运算符(modulo)允许您获取介于0和第二个操作数-1之间的数字