2010-06-14 31 views
1

我刚刚在actionscript 3上试过我的手,并遇到了路障。 我该如何间歇地渲染立方体(cube1),即。交错加载。我需要立方体彼此分开加载。对象间歇/交错加载

下面是我到目前为止的代码段:

var rows:int = 5; 
var cols:int = 3; 
var spacery:int = 100; 
var spacerx:int = 120; 
var box_count:int = 8; 

for(var i:int; i < box_count; i++) {            
    cube1 = new Cube(ml,100,10,80,1,1,1);    
    cube1.y = ((i % rows)) * (cube1.x + spacery); 
    cube1.x = Math.floor(i/rows) * (cube1.x +spacerx); 
    cube1.z = 0; 

    bigBox.addChild(cube1); 
} 
+0

你尝试过一个计时器? – phwd 2010-06-14 13:27:59

回答

2
//Create an array out side the function; as a global (instance) variable: 
var cubes:Array = []; 

//instead of bigBox.addChild(cube1), store them in the array: 
cubes.push(cube1); 

//initialize a timer outside after for loop 
//Fire every 100 milliseconds, box_count times 
var timer:Timer = new Timer(100, box_count); 
timer.addEventListener(TimerEvent.TIMER, onTick); 
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTickDone); 

function onTick(e:Event):void 
{ 
    bigBox.addChild(cubes[timer.currentCount]); 
} 
function onTickDone(e:Event):void 
{ 
    cubes = null; 
    timer.removeEventListener(TimerEvent.TIMER, onTick); 
    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTickDone); 
    timer = null; 
}