I'm clearly missing something here.
I need to fill methods of dynamic AS3 class from an array (see silly example below).
But when I call those methods, all of them appear to be the same method. In the example below, all methods are foobar1
.
If I create methods by hand, without a loop, everything is fine.
Any clues?
package foo
{
public class Bar
{
public function testDynamicClassSanity():void
{
var foo:Foo = new Foo();
var methods:Object = { foobar1: 101, foobar2: 201, foobar3: 301 };
for (var key:String in methods)
{
var val:Number = methods[key];
foo[key] = function():Number
{
return val;
};
}
// Next trace prints
// 101 = 101 201 = 101 301 = 101
trace(
101, "=", foo.foobar1(),
201, "=", foo.foobar2(),
301, "=", foo.foobar3()
);
}
}
}
internal dynamic class Foo
{
};