MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference page 1002

Actionscript 2.0 language reference
Table of Contents

Advertisement

Usage 2: the following example uses
functions. Using
__resolve
.
myFunction
// instantiate a new object
var myObject:Object = new Object();
// define a function for __resolve to call
myObject.myFunction = function (name) {
trace("Method " + name + " was called");
};
// define the __resolve function
myObject.__resolve = function (name) {
return function () { this.myFunction(name); };
};
// test __resolve using undefined method names
myObject.someMethod(); // output: Method someMethod was called
myObject.someOtherMethod(); //output: Method someOtherMethod was called
Usage 3: The following example builds on the previous example by adding the ability to cache
resolved methods. By caching methods,
interest. This allows lazy construction of object methods. Lazy construction is an optimization
technique that defers the creation, or construction, of methods until the time at which a
method is first used.
// instantiate a new object
var myObject:Object = new Object();
// define a function for __resolve to call
myObject.myFunction = function(name) {
trace("Method "+name+" was called");
};
// define the __resolve function
myObject.__resolve = function(name) {
trace("Resolve called for "+name); // to check when __resolve is called
// Not only call the function, but also save a reference to it
var f:Function = function () {
this.myFunction(name);
};
// create a new object method and assign it the reference
this[name] = f;
// return the reference
return f;
};
// test __resolve using undefined method names
// __resolve will only be called once for each method name
myObject.someMethod(); // calls __resolve
myObject.someMethod(); // does not call __resolve because it is now defined
myObject.someOtherMethod(); // calls __resolve
1002 ActionScript classes
as a functor, which is a function that generates
__resolve
redirects undefined method calls to a generic function named
__resolve
is called only once for each method of

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash 8

Table of Contents