Please see code below. I will have a bunch of elements, that I want to run whatever “formula” refers to, for that element. In the code, where it says, “this works”, it works as expected. However I need to fire off these formulas, without naming “firstElement” explicitly. Even though the nested for loop is a little clunky, I think it should work, but it causes the error listed below. How can I fire off the formulas, without naming the elements explicitly? Thanks!
var test:Object = {
element:
[
{ "firstElement":
{
formula:myFunction
}
}
]
}// end test object
public function RunThisFunctionFirst() {
test.element[0].firstElement.formula();//this works
for (var index in test.element){
for (var object in test.element[index]){
trace ("object " + object);// traces "firstElement", as expected
object.formula()// this causes error: Error #1006: value is not a function.
}
}
}
function myFunction (){
trace ("my function called");
}
Regarding the outer loop,
elementis an array, not an object, so you want to usefor(;;)notfor in.Regarding the inner loop,
objectis the string"firstElement"not an object.