PDA

View Full Version : Add children one at a time


angie
10-03-2008, 09:24 AM
In actionscript I have a loop which instantiates some components and adds them to the display list. I want these to be added one at a time, but looking at the creationComplete time they are all completing at the same time. Is there anything I can do to change this behaviour? Example code is below. I've added a delay for demonstration purposes.


private function onCreationComplete():void
{
for (var i:int = 0; i < 4; i++)
{
var d:Date = new Date();
var v:Number = d.valueOf();
do
{
var d2:Date = new Date();
if ((d2.valueOf() - v) > 2000)
break;
} while (1 == 1)
var t:TextInput = new TextInput();
t.addEventListener(FlexEvent.CREATION_COMPLETE, done);
addChild(t); }
}

private function done(evt:FlexEvent):void
{
var d:Date = new Date();
evt.currentTarget.text = d.seconds + " " + d.milliseconds;
}

emogazine
10-06-2008, 04:52 PM
because flex is frame-based so the code (for...loop) to add child will be processed in one frame. What you can do is using Timer. Or using callLater function.