Dynamically Access Properties in Flex

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: