1 Reply Latest reply on Apr 11, 2009 7:59 AM by ergo_eleven

    Advice re: the <mx:TextInput> control

    jcahill23

      Hi. I have created a tab navigator with 6 tabs in a <mx:WindowedApplication>.

      Each tab is a canvas in which sits a text input control.


              <mx:Canvas id="tab0" width="613" height="397" borderColor="#737373">
                  <mx:TextInput x="42" y="134" width="193" id="labelName2" fontFamily="Georgia" />        
              </mx:Canvas>

       

      I don't seem to be able to access/set the labelName0.text from within the <mx:Script> block.


      I thought all flex controls are public instances and their properties can be accessed from anywhere in the code.

       

      What I am trying to do is listen for the "closing" event on WindowedApplication and then put all text inputs into an array which I will then save using AIR and can be reloaded into the text input controls when the app is started again.

      But the error message I keep getting is: "Cannot access a property or method of a null object reference."

      It's driving me nuts!

       

      Thanks.

        • 1. Re: Advice re: the <mx:TextInput> control
          ergo_eleven

          You problem is that you trying to access to object that doesn't created for the time being.

          I.e. the TextArea has not yet created. TabNavigator (and others components) creats its children only when it needed (when you switched on particular tab in case TabNavigator). The shortest way to solve this: set creationPolicy="all" for TabNavigator.

          Try to run this code (with and without creationPolicy):

           

          <mx:Application
               xmlns:mx="http://www.adobe.com/2006/mxml"
               creationComplete="init()">
          
              <mx:Script>
                  <![CDATA[
                      public function init():void
                      {
                           trace(labelName0.text);
                           trace(labelName1.text);
                           trace(labelName2.text);
                      }
                  ]]>
              </mx:Script>
          
              <mx:TabNavigator
                   creationPolicy="all">
                   <mx:Canvas 
                        id="tab0" 
                        label="tab0">
                    <mx:TextInput 
                         id="labelName0" 
                         text="text 1" />
               </mx:Canvas>
               <mx:Canvas 
                       id="tab1" 
                    label="tab1">
                    <mx:TextInput 
                    id="labelName1" 
                    text="text 2" />
               </mx:Canvas>
               <mx:Canvas 
                    id="tab2" 
                    label="tab2">
                    <mx:TextInput 
                         id="labelName2" 
                         text="text 3" />
               </mx:Canvas>
              </mx:TabNavigator>
          
          </mx:Application>
          

           

          It will work, but the elegant way to figure out this problem (IMHO) is to create a public string properties and bind TextArea to it.

           

              <mx:String
                   id="text1"/>
          
               <mx:Binding
                   source="labelName0.text"
                   destination="text1" />
               
               <mx:TextInput
               id="labelName0"
               text="{text1}" />
          

           

           

          When you will read/write componet state, you will refer to text1 property, and you must know nothing about labelName0.text.

           

           

          Cheers!