开发者

Loop through children and display each, as3

开发者 https://www.devze.com 2022-12-25 16:37 出处:网络
How do I loop through all of my children, and display each? I would开发者_运维百科 like to know the best

How do I loop through all of my children, and display each? I would开发者_运维百科 like to know the best way to do this.

my children and container

five children, one plays every sec, 1,2,3, etc.

 var square1:Square1 = new Square1;
 var square2:Square2 = new Square2;
 var square3:Square3 = new Square3;
 var square4:Square4 = new Square4;
 var square5:Square5 = new Square5;

 var container:Sprite = new Sprite;
 addChild(container);
 container.addChild(square1)
 container.addChild(square2)
 container.addChild(square3)
 container.addChild(square4)
 container.addChild(square5)

my timer

 var timly:Timer = new Timer(1000, 5);   
  timly.start();
  timly.addEventListener(TimerEvent.TIMER, onLoop);

Note:

Tried for loop, numChildren -1, and visibility


Here's an idea...

Set the squares to square#.visible = false and put them in an array mySquaresArray.

Then...

function onLoop( e:Event )
{
    curCount = e.target.currentCount;

    if( curCount > 1 ) {
        var previous_square = curCount -2;
        mySquaresArray[previous_square].visible = false;
    }

    var current_square = curCount - 1;
    mySquaresArray[current_square].visible = true;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消