User Guide

668 Chapter 2: ActionScript Language Reference
Object.__resolve
Availability
Flash Player 6.
Usage
myObject.__resolve = function (name:String) {
// your statements here
};
Parameters
name
A string representing the name of the undefined property.
Returns
Nothing
Description
Property; a reference to a user-defined function that is invoked if ActionScript code refers to an
undefined property or method. If ActionScript code refers to an undefined property or method of
an object, Flash Player determines whether the objects
__resolve property is defined. If
__resolve is defined, the function to which it refers is executed and passed the name of the
undefined property or method. This lets you programmatically supply values for undefined
properties and statements for undefined methods and make it seem as if the properties or
methods are actually defined.
This property is useful for enabling highly transparent client/server communication, and is the
recommended way of invoking server-side methods.
Example
The following examples progressively build upon the first example and illustrate five different
usages of the
__resolve property. To aid understanding, key statements that differ from the
previous usage are in bold typeface.
Usage 1: the following example uses
__resolve to build an object where every undefined
property returns the value
"Hello, world!".
// 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 __resolve as a functor, which is a function that generates
functions. Using
__resolve redirects undefined method calls to a generic function named
myFunction.
// instantiate a new object