Question
Dynamically generated functions
Hi Folks
I have asked a similar question before but it does not quite answer this problem.
I wish to dynamically generate functions based on a number generated from xml - in the example below I use var totalCount to represent such a variable.
var totalCount = 4;
for (var i = 1; i<totalCount+1; i++) {
_root["func"+i] = function () {
trace(i);
};
trace(i) // this traces 1,2,3,4
}
if I then have a button "b1" with the following code . . .
b1.onRelease=function(){
_root.func2()
}
. .what I would like to see is '2' traced in the output panel. However, I get '4'
I have asked a similar question before but it does not quite answer this problem.
I wish to dynamically generate functions based on a number generated from xml - in the example below I use var totalCount to represent such a variable.
var totalCount = 4;
for (var i = 1; i<totalCount+1; i++) {
_root["func"+i] = function () {
trace(i);
};
trace(i) // this traces 1,2,3,4
}
if I then have a button "b1" with the following code . . .
b1.onRelease=function(){
_root.func2()
}
. .what I would like to see is '2' traced in the output panel. However, I get '4'