The this keyword in inline functions
I just spent about half an hour trying to figure out why the inline function I used as a parameter for callLater wasn't being executed properly (not even when I tried setTimeout instead).
After this short timespan of mental agony someone pointed out to me that I had to leave out the this keyword of my inline function. And I thought most scope-related problems would have fled with the arrival of Actionscript3.0...
So for the sake of clarity, this is wrong:
-
callLater (function():void{
-
this.myVar = "bla-die-bla";
-
});
..and this is right:
-
callLater (function():void{
-
myVar = "bla-die-bla";
-
});
..well that is unless you intend to execute from within the global scope.
No Responses