Be careful when you name a method ’set’ because this could cause unexpected behaviour. I stumbled across this when trying to figure out why my setAll-method in the org.as2lib.data.holder.list.PriorityList-class was not working. All I did was looping over a list and calling the set-method for each element. But the set-method strangely never got invoked.
-
/**
-
* @author Simon Wacker
-
*/
-
class PriorityList {
-
public function set(index:Number, value):Void {
-
trace("About to invoke set(..).");
-
}
-
public function setAll(Void):Void {
-
set(0, "value");
-
}
-
}
As you can see there are only two methods ’setAll’ and ’set’. And the setAll-method calls the set-method. One would expect the output ‘About to invoke set(..).’ when using the following test code.
-
var list:PriorityList = new PriorityList();
-
list.setAll();
But what happens is actually - nothing. You must change the call to the set-method as follows.
-
/**
-
* @author Simon Wacker
-
*/
-
class PriorityList {
-
public function set(index:Number, value):Void {
-
trace("About to invoke set(..).");
-
}
-
public function setAll(Void):Void {
-
this.set(0, "value");
-
}
-
}
Note the added ‘this’.
So, be careful when naming your methods like a keyword.
