MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 383

Actionscript language reference
Table of Contents

Advertisement

// 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) {
trace("Method "+name+" was called");
};
// define the __resolve function
myObject.__resolve = function(name) {
// reserve the name "onStatus" for local use
if (name == "onStatus") {
return undefined;
}
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 the method name "onStatus"
trace(myObject.onStatus("hello"));
// output: undefined
Usage 5: The following example builds on the previous example by creating a functor that accepts
parameters. This example makes extensive use of the
methods of the
Array class
// instantiate a new object
var myObject:Object = new Object();
// 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
// to check when __resolve is called
.
, and uses several
arguments object
Object.__resolve
383

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents