Property | Defined By | ||
---|---|---|---|
frameCallbacks : ICallbackCollection [read-only]
These callbacks get triggered once per frame. | IScheduler |
Method | Defined By | ||
---|---|---|---|
callLater(relevantContext:Object, method:Function, parameters:Array = null):void
This calls a function later using setTimeout(method, 0). | IScheduler | ||
startTask(relevantContext:Object, iterativeTask:Function, priority:uint, finalCallback:Function = null, description:String = null):void
This will start an asynchronous task, calling iterativeTask() across multiple frames until it returns a value of 1 or the relevantContext object is disposed. | IScheduler |
frameCallbacks | property |
frameCallbacks:ICallbackCollection
[read-only] These callbacks get triggered once per frame.
public function get frameCallbacks():ICallbackCollection
callLater | () | method |
public function callLater(relevantContext:Object, method:Function, parameters:Array = null):void
This calls a function later using setTimeout(method, 0).
Parameters
relevantContext:Object — The 'this' argument for the function. If the relevantContext object is disposed, the function will not be called.
| |
method:Function — The function to call later.
| |
parameters:Array (default = null ) — The parameters to pass to the function.
|
startTask | () | method |
public function startTask(relevantContext:Object, iterativeTask:Function, priority:uint, finalCallback:Function = null, description:String = null):void
This will start an asynchronous task, calling iterativeTask() across multiple frames until it returns a value of 1 or the relevantContext object is disposed.
Parameters
relevantContext:Object — This parameter may be null. If the relevantContext object gets disposed, the task will no longer be iterated.
| |
iterativeTask:Function — A function that performs a single iteration of the asynchronous task.
This function must take zero or one parameter and return a number from 0.0 to 1.0 indicating the overall progress of the task.
A return value below 1.0 indicates that the function should be called again to continue the task.
When the task is completed, iterativeTask() should return 1.0.
The optional parameter specifies the time when the function should return. If the function accepts the returnTime
parameter, it will not be called repeatedly within the same frame even if it returns before the returnTime.
It is recommended to accept the returnTime parameter because code that utilizes it properly will have higher performance.
| |
priority:uint — The task priority, which should be one of the static constants in WeaveAPI.
| |
finalCallback:Function (default = null ) — A function that should be called after the task is completed.
| |
description:String (default = null ) — A description for the task.
|
var array:Array = ['a','b','c','d']; var index:int = 0; function iterativeTask():Number // this may be called repeatedly in succession { if (index >= array.length) // in case the length is zero return 1; trace(array[index]); index++; return index / array.length; // this will return 1.0 on the last iteration. }
var array:Array = ['a','b','c','d']; var index:int = 0; function iterativeTaskWithTimer(returnTime:int):Number // this will be called only once in succession { for (; index < array.length; index++) { // return time check should be at the beginning of the loop if (getTimer() > returnTime) return index / array.length; // progress so far // process the current item trace(array[index]); } return 1; // loop finished }
var outerArray:Array = [['a','b','c'], ['aa','bb','cc'], ['x','y','z'], ['xx','yy','zz']]; var outerIndex:int = 0; var innerArray:Array = null; var innerIndex:int = 0; function iterativeNestedTaskWithTimer(returnTime:int):Number // this will be called only once in succession { for (; outerIndex < outerArray.length; outerIndex++) { // return time check can go here at the beginning of the loop, but we already have one in the inner loop if (innerArray == null) { // time to initialize inner loop innerArray = outerArray[outerIndex] as Array; innerIndex = 0; // more code can go inside this if-block that would normally go right before the inner loop } for (; innerIndex < innerArray.length; innerIndex++) { // return time check should be at the beginning of the loop if (getTimer() > returnTime) return (outerIndex + (innerIndex / innerArray.length)) / outerArray.length; // progress so far // process the current item trace('item', outerIndex, innerIndex, 'is', innerArray[innerIndex]); } innerArray = null; // inner loop finished // more code can go here to be executed after the nested loop } return 1; // outer loop finished }