2 Replies Latest reply on Jan 12, 2011 11:48 AM by Flex harUI

    how to clear text fields when the user navigates back to the screen




      Does anyone have any idea on how to clear the text input fields and dropdown boxes when the user navigates back to the screen, say for e.g. create screen?

      My issue is that i have plenty of fields in the create screen within a form. Is there a way to avoid programaticaly blanking out every field and just do it at the form level using an api to reset to a state before the user entry?



        • 1. Re: how to clear text fields when the user navigates back to the screen
          Gregory Lafrance Level 6

          This code allows you to make it more generic, and you would need to tweak it if there are more than TextInput controls, but it should provide some ideas.


          As far as using states, you could use SetProperty to set the text to empty, but that might be messier.


          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                import mx.containers.FormItem;
                import mx.controls.TextInput;
                import mx.events.IndexChangedEvent;
                import mx.core.Container;
                private function clearSreen(evt:IndexChangedEvent):void{
                  var view:Container = tn.selectedChild as Container;
                  for each(var child:Object in view.getChildren()){
                    if(child is FormItem){
                      var subchild:DisplayObject = child.getChildAt(0);
                      if(subchild is TextInput){
                        TextInput(subchild).text = "";
            <mx:TabNavigator id="tn" resizeToContent="true"
              <mx:Form id="frm1" label="View Number One">
                <mx:FormItem label="First name:">
                <mx:FormItem label="Last name:">
              <mx:Form id="frm2" label="View Number Two">
                <mx:FormItem label="Address1:">
                <mx:FormItem label="Address2:">
                <mx:FormItem label="City:">
                <mx:FormItem label="State:">
                <mx:FormItem label="Zip code:">


          If this post answers your question or helps, please mark it as such. Thanks!

          Adobe Flex Development and Support Services

          1 person found this helpful
          • 2. Re: how to clear text fields when the user navigates back to the screen
            Flex harUI Adobe Employee

            If you have a model-view or MVC architecture, you would reset the model

            maybe by re-instantiating a new instance.