Skip to main content
October 13, 2013
Answered

Displaying text from Combobox as typing?

  • October 13, 2013
  • 1 reply
  • 738 views

Hi

I am making a standalone text field display the full word as the user types, but the word has to be from the choices in a ComboBox.

So as they type "a", if the first choice in the ComboBox is "apple", apple is displayed in the text box. Then they type "aw", then if "aware" is the first "aw' word in the combobox, aware is displayed etc

I'm about 1/3 the way through coding it, and thought I'd ask here is there is a standard way of doing this?

This topic has been closed for replies.
Correct answer moccamaximum

//for simplicity`s sake I use strings, if you have a Combo´Box with a DataProvider simply use that instead

var strings:Array = ["america","australia","alligator","anchorman"];

strings.sort();

tf.addEventListener(Event.CHANGE, autocomplete);

function autocomplete(e:Event):void

{

    var input:Array = e.target.text.split("");

    for (var i:uint = 0; i<input.length; i++)

    {

        for (var j:uint = 0; j<strings.length; j++)

        {

            for (var k:uint = 0; k<strings.length; k++)

            {

                var arrstrings:Array = strings.split("");

                if (input == arrstrings)

                {

                    e.target.text = strings;

                    e.target.setSelection(0,e.target.text.length);

                    return;

                }

                else

                {

                    e.target.text = "NO MATCH FOUND";

                    e.target.setSelection(0,e.target.text.length);

                }

            }

        }

    }

}

1 reply

moccamaximumCorrect answer
Inspiring
October 14, 2013

//for simplicity`s sake I use strings, if you have a Combo´Box with a DataProvider simply use that instead

var strings:Array = ["america","australia","alligator","anchorman"];

strings.sort();

tf.addEventListener(Event.CHANGE, autocomplete);

function autocomplete(e:Event):void

{

    var input:Array = e.target.text.split("");

    for (var i:uint = 0; i<input.length; i++)

    {

        for (var j:uint = 0; j<strings.length; j++)

        {

            for (var k:uint = 0; k<strings.length; k++)

            {

                var arrstrings:Array = strings.split("");

                if (input == arrstrings)

                {

                    e.target.text = strings;

                    e.target.setSelection(0,e.target.text.length);

                    return;

                }

                else

                {

                    e.target.text = "NO MATCH FOUND";

                    e.target.setSelection(0,e.target.text.length);

                }

            }

        }

    }

}

October 17, 2013

Thanks Mocca. This was the pefect framework to get me going.