Loop through children and display each, as3
Posted
by VideoDnd
on Stack Overflow
See other posts from Stack Overflow
or by VideoDnd
Published on 2010-03-30T13:55:59Z
Indexed on
2010/03/30
15:33 UTC
Read the original article
Hit count: 280
flash
|actionscript-3
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
ERROR 'access of undefined property'
//Thomas's idea
var timly:Timer = new Timer(1000, 10);
timly.start();
timly.addEventListener(TimerEvent.TIMER, onLoop, false, 0, true);
//
var square1:Square1 = new Square1;
square1.visible = false
container.addChild(square2)
var square2:Square2 = new Square2;
square2.visible = false
container.addChild(square3)
var square3:Square3 = new Square3;
square3.visible = false
container.addChild(square3)
var square4:Square4 = new Square4;
square4.visible = false
container.addChild(square4)
var square5:Square5 = new Square5;
square5.visible = false
container.addChild(square5)
var container:Sprite = new Sprite;
this.addChild(container);
var curCount:Number = 100;
//
function collectChildren(container:DisplayObjectContainer):Array {
var len:int = container.numChildren;
var mySquaresArray:Array = [];
for (var i:int = 0; i < len; i++)
{
mySquaresArray.push(container.getChildAt(i).name);
}
return mySquaresArray;
}
//
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;
}
© Stack Overflow or respective owner