Having a strong C++ background, I wonder how this works in Actionscript :
class A {
public function callme():void {
}
public function foo():void {
var a:Function = callme;
a();
}
}
The question is : does Actionscript “secretly” pass an object pointer alongside the function pointer?
Here is another question : is it possible to do something like this (pseudocode) :
class A {
public function callme():void {
}
public function foo():void {
var a:Function = callme;
var classAinstance:A = new A();
classAinstance.a();
}
}
i.e have separate function and object pointers.
Yes, Flash does pass the object context along with the function pointer. This hasn’t always been the case, but is true as of ActionScript 3.0. See here:
http://www.adobe.com/devnet/actionscript/articles/actionscript3_overview.html
Method closures
As far as your second question, if you want to run a method in the context of a different object, then use
.call()or.apply().http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Function.html?filter_coldfusion=9&filter_flex=3&filter_flashplayer=10&filter_air=1.5