Как переместить детей в MovieClip? - PullRequest
0 голосов
/ 14 октября 2011

У меня есть контейнер mc с 5 дочерними mcs.

дочерние имена 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]

Ответы [ 2 ]

1 голос
/ 14 октября 2011

Давайте введем переменную смещения, имитирующую прогрессию вращения:

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);
}

Оператор% (по модулю) позволяет получить число от 0 до второго операнда-1

1 голос
/ 14 октября 2011
//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;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...