So I am looking to create an autocomplete textfield (a lã google) that creates it’s suggestions based on xml nodes. So far I have code in place thats uses a txt file (which is fine and dandy but I already have the xml fully complete and use it elsewhere).
When I swap the .txt file with the xml file I get no errors but I also don’t get any suggestions… Still learning here so any help, thoughts, ideas are helpfull (especially when explained to me)
public function Main():void {
urlLoader.load(new URLRequest("Sports.txt"));
urlLoader.addEventListener(Event.COMPLETE, loadComplete);
inputField.addEventListener(KeyboardEvent.KEY_UP, suggest);
format.font = "Helvetica";
format.size = 12;
format.bold = true;
}
private function loadComplete(e:Event):void
{
suggestions = e.target.data.split(",");
// here i've swapped 9"," with ("
")
}
private function suggest(e:KeyboardEvent):void
{
suggested = [];
for (var i:int = 0; i < textfields.length; i++)
{
removeChild(textfields*);
}
textfields = [];
for (var j:int = 0; j < suggestions.length; j++)
{
if (suggestions[j].indexOf(inputField.text.toLowerCase()) == 0)
{
var term:TextField = new TextField();
//here i define my textformat
if (inputField.length == 0)
{
suggested = [];
for (var k:int = 0; k < textfields.length; k++)
{
removeChild(textfields[k]);
}
textfields = [];
}
if(e.keyCode == Keyboard.DOWN && currentSelection < textfields.length-1)
{
currentSelection++;
textfields[currentSelection].textColor = 0xFFCC00;
}
if(e.keyCode == Keyboard.UP && currentSelection > 0)
{
currentSelection--;
textfields[currentSelection].textColor = 0xFFCC00;
}
if(e.keyCode == Keyboard.ENTER)
{
inputField.text = textfields[currentSelection].text;
suggested = [];
for (var l:int = 0; l < textfields.length; l++)
{
removeChild(textfields[l]);
}
textfields = [];
currentSelection = 0;
}
}
// it goes on to repeat these keyboard functions with mouse equivalents as well