In Flex 4 how do I get a list of components in my application
I have an application that presents a form that accepts many data items. I would like to "dim out" those non required fields that have not been completed (by setting the alpha to ".5"). I was thinking of creating an array and manually entering all the TextInputs and CheckBoxes etc but then I thought there might/should be a way of getting a list of all components and controls in my application. I have done some research but have not found the answer yet - I will continue to look. While looking on my own I开发者_JAVA百科 thought I would ask the question here. Thanks for any guidance.
I recommend you look into using the Form and FormElement containers from the mx package. These will work in flex4. This allows you to setup validation and required fields very easily. Here is the documentation.
After reading you comment, it sounds easy. You can loop through Form elements. It is different for MX Form and Spark Form.
var listOfElements:Array = [];
var formItem:FormItem;
for (var i:int = 0; i < myForm.numElements; i++) //myForm.numChildren for MX
{
formItem = myForm.getElementAt(i) as FormItem; //myForm.getItemAt(i) for MX
if(formItem)
{
trace("setting alpha for",formItem.name);
formItem.alpha = 0.5;
listOfElements.push(formItem);
}
}
精彩评论