MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference page 561

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

Usage 1: the following example uses
property returns the value
// instantiate a new object
var myObject:Object = new Object();
// define the __resolve function
myObject.__resolve = function (name) {
return "Hello, world!";
};
trace (myObject.property1); // output: Hello, world!
trace (myObject.property2); // output: Hello, world!
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 () {
__resolve
.
"Hello, world!"
__resolve
redirects undefined method calls to a generic function named
__resolve
to build an object where every undefined
as a functor, which is a function that generates
is called only once for each method of
Object
561

Advertisement

Table of Contents
loading

Table of Contents