views:

1204

answers:

2

I have an editable ComboBox component and I want to reference the TextInput that is shown, in order to programmatically select the Text in it. This is very straightforward on a TextInput:

private function selectNameText():void
{
    nameTextInput.selectionBeginIndex = 0;

    nameTextInput.selectionEndIndex = nameTextInput.text.length;
}

But I can't find any way to access the TextInput of an editable ComboBox.

+1  A: 

It seems that referencing the TextInput for THIS reason is unnecessary, since the text is selected by default.

Eric Belair
A: 

I ran into this problem when using a ComboBox as a DataGrid itemRenderer. If you need to reference the TextInput you can override ComboBox and create a getter that returns the protected textInput. In my case I needed to prevent the auto-selection that occurs when a ComboBox is editable. Looking at ComboBox, this occurs during updateDisplayList so this should do the trick:

package com.whatever.controls
{

import mx.controls.ComboBox;

public class EditableComboBox extends ComboBox
{

 public function EditableComboBox()
 {
  super();
 }

 override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
 {
  super.updateDisplayList(unscaledWidth, unscaledHeight);

  if (editable)
  {
   textInput.selectionBeginIndex = text.length;
   textInput.selectionEndIndex  = text.length;
  }
 }

}
}
Mark Tomsu