开发者

slowing down a loop in a recursive function

I have a difficult problem with a recursive function. Essentially I need to 'slow down' a for loop within a function that repeatedly calls itself(the function); Is this possible, or do I need to somehow extract the recursive nature of the function?

function callRecursiveFuncAgain(ob:Object):void{
    //do recursive stuff;
    for (var i:int = 0; i < 4; i++) {
    开发者_如何学编程    _nextObj=foo
    callRecursiveFuncAgain(_nextObj);
    }
}


Try setTimeout

function callRecursiveFuncAgain(ob:Object):void{
 // do recursive stuff
 var i = 0;
 function callNext()
 {
   if(i++ < 4)
   {
     _nextObj=foo;
     callRecursiveFuncAgain(_nextObj);
     setTimeout(callNext, 1000);
   }
 }
 callNext();
}


You should use some function which will wait for some time or another function which will use much CPU and therefore will slow down your recursive function. Another way would be using debugger and breakpoints.


Are you serious? If you have a slow computer your CPU will have more load then a fast CPU which will NEVER work in a situation that needs a good solution. It's not even close to a crappy solution.

Try to use the setTimeOut that's in the flash.utils package http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html.

example use: setTimeout(delayedFunction, delay, arguments); Note that the delay is expressed in milliseconds.

Check the 'clearTimeOut()' function (flash.utils) to clear your setTimeOut when you're done with it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜