I know that in flash you can pass objects or movie clip references as arguments to a function. but you cant (as far as i can tell) send a function reference as an argument to a function.
[tt][blue]
myFunction(10, myOtherFunction() );
//this is obviously no good because it would send the final product of myOtherFunction(),not a reference to it.
[/blue][/tt]
It also seems like you cant cheat it by sending the function name as a string, then doing an eval on it to invoke the function,
[tt][blue]
myFunction(10, "myOtherFunction(5)" );
function myFunction(x,y) {
eval
;
}
//be great if this worked, but no good
[/blue][/tt]
because eval(expression) only works when the (expression) is a variable name. eval("5+5") wont give you 10. similarly if you pass a string "process(10)" as an argument , it seems there is no way of getting back from that string to running code. It seems like a huge mistake not have a function that will take the value of any string and simply run it as code. do you know of any such thing?
i wanted to do something pretty simple, just make a generic timer function that i could pass a function reference and a couple variables and it would run the function every (x) frames for
iterations.
there is problably a simpler way of accomplishing this that im not familiar with or thinking of, but any advice on the [blue]"function timer" function[/blue] or the [blue]passing of function reference[/blue] or the [blue]switching from a string to running code[/blue] issue much appreciated.
thanks> otrain
[tt][blue]
myFunction(10, myOtherFunction() );
//this is obviously no good because it would send the final product of myOtherFunction(),not a reference to it.
[/blue][/tt]
It also seems like you cant cheat it by sending the function name as a string, then doing an eval on it to invoke the function,
[tt][blue]
myFunction(10, "myOtherFunction(5)" );
function myFunction(x,y) {
eval
}
//be great if this worked, but no good
[/blue][/tt]
because eval(expression) only works when the (expression) is a variable name. eval("5+5") wont give you 10. similarly if you pass a string "process(10)" as an argument , it seems there is no way of getting back from that string to running code. It seems like a huge mistake not have a function that will take the value of any string and simply run it as code. do you know of any such thing?
i wanted to do something pretty simple, just make a generic timer function that i could pass a function reference and a couple variables and it would run the function every (x) frames for
there is problably a simpler way of accomplishing this that im not familiar with or thinking of, but any advice on the [blue]"function timer" function[/blue] or the [blue]passing of function reference[/blue] or the [blue]switching from a string to running code[/blue] issue much appreciated.
thanks> otrain