Archive for July, 2010

Dynamically Access Properties in Flex

July 27, 2010

I was working on modularizing my actionscript code, by grouping similar tasks in same function. But I came across a problem, where I need to set the values of different properties of the same class.
For eg. I am having code sequence like :

var bot:BottomVO = new BottomVO();
bot.variable1 = (var2*var3)/100;
array.addItem(bot);
bot = new BottomVO();
bot.variable2 = (var2*var3)/100;
array.addItem(bot);

Here the same values(or calculation of same variables) are set into two different properties of one class. We can use a same method to do this.

:
:
array.addItem(calc(‘variable1’));
array.addItem(calc(‘variable2’));
:
:

private function calc(var2:*,var3:*,prop:String):BottomVO{
var bot:BottomVO = new BottomVO();
bot[prop] = (var2*var3)/100;
return bot;

}

Happy Coding 🙂

For more reference : http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f32.html