I was in the process of completing my DropDownMenu class and I needed a way to save the information of the selected item in the list and the best thing would be to use the getter functions. In my later posts you'll see the dropDownMenu but for right now to give you an idea, we would need the following details to be accessible when an item is selected:
lable, detail, thumb, data and index.
So, if we used the getter functions normally, I had to create something like below 5 times!
public function get index():int
{
return _index;
}
It may work, but we can do something better, to save the data all in an object and use only one getter function and extract the kind of details we'd like to see.
In order to do so, you should do the following in your Class file. First introduce your object with all of the information you want to save in it, easily like this:
private var _selectedItem:Object = {lable:"EMPTY", detail:"EMPTY", thumb:"EMPTY", data:"EMPTY", index:0};
it will be very easy to overwrite the values of an object, as an example, you are able to set values to such an object like this:
_selectedItem.data = "some data here!";
ok, and after you have the object ready you should write your getter function like this:
public function get selectedItem():Object
{
return _selectedItem;
}
easy right?
you don't have to write several getters now and you will call the getter function from outside of the class like this:
trace(the Class.selectedItem.index);
trace(myCombo.selectedItem.lable);
trace(myCombo.selectedItem.detail);
trace(myCombo.selectedItem.thumb);
trace(myCombo.selectedItem.data);
That's it, I hope you like this idea.
Regards,
Hadi

My Flash Lab
January 25th, 2009 9:16 pm
[...] It may work, but we can do something better, to save the data all in an object and use only one getter function and extract the kind of details we’d like to see. In order to do so, you should do the following in your Class file Read more [...]
January 26th, 2009 2:00 pm
ok, the example above does the same thing, doesn’t it? it will save data in an object and we can call the getter function and the specific item in the object…
August 19th, 2010 5:22 pm
…
thanks for sharing the info…..
August 29th, 2010 10:44 am
…
Many thanks with the well-thought posting. I’m in fact at work correct now! So I need to go off with no examining all I’d like. But, I set your website on my RSS feed to ensure that I can understand much more….
August 29th, 2010 10:49 am
get more here at our new website: http://www.myflashlab.com