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);
// 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();
myObject.someMethod();
myObject.someOtherMethod();
myObject.someOtherMethod();
Usage 4: The following example builds on the previous example by reserving a method name,
, for local use so that it is not resolved in the same way as other undefined properties.
onStatus()
Added code is in bold typeface.
// instantiate a new object
var myObject:Object = new Object();
// define a function for __resolve to call
myObject.myFunction = function(name) {
__resolve
// to check when __resolve is called
// calls __resolve
// does not call __resolve because it is now defined
// calls __resolve
// does not call __resolve, no longer undefined
is called only once for each method of
Object.__resolve
669
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?