I miss this part on Flex 4.x, since in Flex 3.x you easily loop throw Form Items and their fields, which was in compensation of getChildren().
Since we have in Flex 4.x a Skin architecture diffs from Flex 3 , we no longer have getChildren(), and just leave us an option numElements.
Hard for may developers out there and makes you opt-in for statis solution, on naming it all form itens and clear them all in a function. Don’t be shame if you already did that, it’s normal when you don’t know deep in on Flex SDK.
All right, I want to share with you guys, a little Manager Class, which I called, FormManager to workaround on that situation, and get rid of that.
//////////////////////////////////////////////////////////////////////////////// // // RIACYCLE INC. LTDA BRAZIL // Copyright 2011 RIACycle Inc. LTDA // All Rights Reserved. // // NOTICE: RIACycle Inc. permits you to use, modify, and distribute this file // in accordance with the terms of the license agreement accompanying it. // Code Licensed by MPL http://www.opensource.org/licenses/MPL-1.1 // // Author: Igor Costa // //////////////////////////////////////////////////////////////////////////////// package { import mx.collections.ArrayList; import mx.core.IVisualElementContainer; import mx.core.UIComponent; import spark.components.ComboBox; import spark.components.Form; import spark.skins.spark.ComboBoxSkin; public class FormManager { public function FormManager() { } private static var _numelements:ArrayList; /** * @public * Static method to clear all values filled in a given Form * * Usage FormManager.clearFields(myForm); * @see spark.components.Form; * @see mx.core.IVisualElementContainer; * */ public static function clearFields(value:Form):void { for (var i:int = 0 ;i <= value.numElements-1;i++) { var item:IVisualElementContainer = value.getElementAt(i) as IVisualElementContainer; for (var j:int = 0; j<=item.numElements-1;j++) { var input:UIComponent = item.getElementAt(j) as UIComponent; if(input.hasOwnProperty('text')) input['text'] = ''; if(input.hasOwnProperty('textFlow')) input['textFlow'] = null; if(input.hasOwnProperty('selectedItem')) input['selectedItem'] = null; if(input is ComboBox) ComboBox(input).textInput.text =''; // fix the bug on default ComboBoxSkin class if(input.hasOwnProperty('selectedItems')) input['selectedItems'] = null; if(input.hasOwnProperty('selectedIndex')) input['selectedIndex'] = -1; if(input.hasOwnProperty('selected')) input['selected']= false; } } } /** * @public * Static method to return an ArrayList of all fields in a given Form * * Usage : var elements:ArrayList = FormManager.getElements(myForm); * for each (var item:* in elements) * { * trace(item); * } * @see spark.components.Form; * @see mx.core.IVisualElementContainer; * */ public static function getElements(value:Form):ArrayList { _numelements = new ArrayList(); for (var i:int = 0 ;i <= value.numElements-1;i++) { var item:IVisualElementContainer = value.getElementAt(i) as IVisualElementContainer; for (var j:int = 0; j<=item.numElements-1;j++) { var input:UIComponent = item.getElementAt(j) as UIComponent; _numelements.addItem(input); } } return _numelements; } } }

