ASAP Framework has a follow-up: go to ASAP Library for our AS3 framework!

ASAP Framework has a follow-up: go to ASAP Library for our AS3 framework!

Consequence of new interface for FrameDelay

25 Jun 2007 - 21:13:28 by StephanBezoen in ActionScript3
A very nice new feature of ActionScript 3 is the function closure. Basically this means that when a function is passed as a parameter, it brings with it a backpack containing its owner, so when called, it will run itself inside its original scope. This is very handy when used for event handling, but can also be used on other occasions. One of those occasions is FrameDelay? class. This class allows you to call a function after one or more enterFrame-events. In the new AS3 version, the object that contains the function to be called, no longer can be passed as a parameter. In most use cases, this should be fine, since the function acts as a kind of event handler, and doesn't need explicit scoping. There is, however, one caveat to this. The implementation inside the FrameDelay? class now runs the function by placing brackets (()) behind the parameter if there are no arguments specified, or brackets plus arguments ((args)) if there are arguments. The arguments are passed as an Array. Now calling a function directly does not dissect the array into its separate parameters. Therefore the function is called with a single array of parameters. In the AS2 implementation of FrameDelay? , the method Function.apply(object, args) was used, which does dissect the array into its separate parameters.

An option here is to add an optional parameter to the FrameDelay? constructor. When this is passed and parameters are passed, Function.apply(object, args) is used; otherwise the function can be called directly.

As of now I'm not aware of any differences in performance, but since the FrameDelay? is mostly used to wait a single enterFrame, there doesn't seem to be much need for an indepth investigation right now.

Be aware though, when using the development version of the framework, that interfaces of classes may be subject to rigorous change smile

Comments

 

Topic revision: r2 - 08 Sep 2007 - 18:55:15 - ArthurClemens

New site visitors: register here
Registered users may edit pages on this site.
Registration is free!
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding ASAP? Send feedback