1 Reply Latest reply on Feb 12, 2008 3:23 PM by Ryan_Mayberry

    Updating TextInput from Component

      I'm pretty new to Flex so I'm not certain if I'm missing something obvious or if I'm just going about this the wrong way.

      I'm building a touch screen application using Flex and have built a small QWERTY component which will let people type in some info into the touch screen. Everything works visually although when I try and access the 'text' property of the TextInput object it is always blank even tho I can clearly see the value in the field.

      Here is a brief summary of how the component and code is set up.

      MXML File which makes use of the qwerty component.
      Alert.show(myinput.text) Never shows any results even tho visually the 'text'
      property appears to update and shows expected value
      <mx:TextInput id="myinput" text="" /> <mx:Button label="test" click="Alert.show(myinput.text)"/>
      <custom:Qwerty inputControl="{myinput}"/>

      Summary of the Qwerty component.
      Full code available upon request.
      public var inputControl:Object;

      private function updateControl(event:Event):void
      inputControl.text += Button(event.target).label;

      <mx:Button label="A" click="updateControl(event)"/>
      <mx:Button label="B" click="updateControl(event)"/>
      <mx:Button label="C" click="updateControl(event)"/>
      <mx:Button label="D" click="updateControl(event)"/>
      <!-- END CODE EXAMPLE -->
        • 1. Re: Updating TextInput from Component
          Ryan_Mayberry Level 1
          Ah.. It appears I have just solved my problem.

          Not seen in my example I was actually assigning the ' inputControl ' property of my component by using an event.target

          example of code which wasn't working as expected.

          private function assignQwertyControl( event:Event ){
          myqwerty.inputControl = event.target;
          <mx:TextInput focusIn="assignQwertyControl(event)" />

          A fix which appears to work

          private function assignQwertyControl( myinput:UIComponent ){
          myqwerty.inputControl = myinput;
          <mx:TextInput id="mytxtinput" focusIn="assignQwertyControl(mytxtinput)" />

          I hope that makes sense. I hate it when I solve my own problem after posting in a forum. Hopefully this is helpful to others. I'll make my QWERTY component available upon request.