- 最后登录
- 2024-6-3
- 注册时间
- 2009-10-16
- 阅读权限
- 100
- 积分
- 18803
- 纳金币
- 17488
- 精华
- 1
|
Delayed Execution (Script Utilities Behavior)
Summary
Provides the ability to call a function after a certain delay.
Category
Latest Behaviors
Author
Gavin Kistner
Difficulty
(Reference)
Time to Complete
5 Minutes
Downloads
Click Here
to download the associated files.
(This document covers version 1.0.1 of the 'Delayed Execution' behavior, current as of 2005-Feb-11)
Description
This utility library adds the ability to call a function after a certain number of frames or number of seconds have passed.
The supplied callback function will be***cuted in the scope of whatever object invoked the
frameDelayedExecute(...)
or
timeDelayedExecute(...)
methods. These methods are available on every object, including globally.
To use, include this behavior anywhere in the scene, and then:
frameDelayedExecute( myFunctionName, 30 );
//function will***n in global scope 30 frames from now
this.frameDelayedExecute( myFunctionName, 30 );
//function will***n in the current scope
otherObj.timeDelayedExecute( this.doStuff, 5 );
//My method will***n in the scope of otherObj
//in 5 seconds
You can cancel a delayed callback by storing the return value from
frameDelayedExecute()
or
timeDelayedExecute()
, and then passing that value to
cancelDelayedExecute()
:
this.delayID = this.frameDelayedExecute( 5, closeMenu );
...
if ( userMovedOverMenu )
{
cancelDelayedExecute( delayID );
}
Note that the
cancelDelayedExecute()
method is available only as a global function; each returned
delayID
is unique, and hence cancelling the delayed callback is not dependant upon the object whose scope it is set to***n inside of.
If you change your mind and want the callback to***n immediately instead of later, pass ***e as a second parameter to
cancelDelayedExecute()
:
cancelDelayedExecute( delayID, ***e );
//Invokes the callback immediately,
//and prevents it from being called later
Demonstration
View Demonstration Project
Download Project File
|
|