2 Replies Latest reply on Mar 11, 2010 10:41 AM by shanflex

    mx:inputText value automatically set to a variable

    shanflex

      Hi,

       

      More of a newbie question ( i wasnt able to figure out much by googling), appreciate your response. Im using AS 3.0 + Flash 10

       

      I have a input control like the following

       

      <mx:TextInput id="txt_name" text="{name}"/>

       

       

      Now, lets say a user types in something to this inputText, i would like the variable 'name' be automatically set to that value. Is there any way of doing that?  I keep coming across examples which manually access value through the id.text and sets it to the variable, like the following

       

      //onclick of some button

      name = txt_name.text

       

      Please let me know if my question is not too clear.

       

      Thanks

      Shankar

        • 1. Re: mx:inputText value automatically set to a variable
          Matt Le Fevre Level 4

          you'll want to update the string variable on the change event of the text input

           

           

          try this:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
              <mx:Script>
                  <![CDATA[
                      
                      [Bindable]
                      public var testString:String = "example text";
                      
                  ]]>
              </mx:Script>
              
              
              <mx:TextInput id="txt1" text="{testString}" change="{testString = txt1.text}" x="81" y="107" width="434"/>
                  
              <mx:Label x="81" y="169" text="Variable name = {testString}"/>
              
          </mx:Application>
          
          
          1 person found this helpful
          • 2. Re: mx:inputText value automatically set to a variable
            shanflex Level 1

            thanks for your response but i was trying to see if that can happen automatically without needing to write this code by setting an attribute on the input component or something..