Object.__resolve
383
// 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
myObject.someOtherMethod(); // does not call __resolve, no longer undefined
Usage 4: The following example builds on the previous example by reserving a method name,
onStatus()
, for local use so that it is not resolved in the same way as other undefined properties.
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); // 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 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
arguments object
, and uses several
methods of the
Array class
.
// instantiate a new object
var myObject:Object = new Object();
Summary of Contents for FLEX-FLEX ACTIONSCRIPT LANGUAGE
Page 1: ...Flex ActionScript Language Reference...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Page 135: ...case 135 See also break default strict equality switch...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Page 808: ...808 Chapter 7 ActionScript for Flash...
Page 810: ...810 Appendix A Deprecated Flash 4 operators...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Page 822: ...822 Index...