Wednesday, 25 January 2012

AS3: Delay code execution

Rather than push loads of code through at the same time, it can be advantageous to delay execution of certain blocks of code:
import flash.utils.*;

var delayStart = setInterval(startCode,3000);

function startCode():void {
    // insert delayed code here

    // stop setInterval repeating
    clearInterval(delayStart);
}
This is useful to remember as a swf may have a lot to do upon initial load (drawing graphics on screen, preparing data structures etc.) So to delay an animation or resource intensive task may be a smart thing to do.

No comments:

Post a Comment