I've got a suggestion field in my app. The code was, so far, working (or I thought it was). It's linked to a txt file. Each sentences in the text file are seperate by a #; Example : Hi#How are you?#Good job# I've got 175 sentences. Weirdly, if I enter "N" for "Non",the code is working and suggest me every sentences with the letter N But if I, then, enter "No", the sentence "Non" (and lot of other with letters "No") isn't suggested anymore ! And it does that with a lot of sentences.... Here's my code : function checkKeypress(event: KeyboardEvent): void {
if (event.keyCode == Keyboard.BACK) {
trace("back pushed");
for (var l:int = 0; l < textfields.length; l++)
{
removeChild(textfields[l]);
}
suggested = [];
textfields = [];
currentSelection = 0;
}
}
function loadComplete(e:Event):void
{
if(drehuLang ==true){
suggestions = e.target.data.split("#");
}else{
suggestions = e.target.data.split(",");
}
}
function suggest(e:KeyboardEvent):void
{
suggested = [];
for (var i:int = 0; i < textfields.length; i++)
{
removeChild(textfields[i]);
}
textfields = [];
for (var j:int = 0; j < suggestions.length; j++)
{
if (suggestions[j].indexOf(inputField.text.toLowerCase()) != -1)
{
var term:TextField = new TextField();
term.width = 360;
term.height = 24;
term.x = 18;
term.y = (24 * suggested.length) + 83;
term.border = true;
term.borderColor = 0x353535;
term.background = true;
term.backgroundColor = 0xFF9900;
term.textColor = 0x4C311D;
term.defaultTextFormat = format;
term.addEventListener(MouseEvent.MOUSE_UP, useWord);
term.addEventListener(MouseEvent.MOUSE_OVER, hover);
term.addEventListener(MouseEvent.MOUSE_OUT, out);
term.addEventListener(MouseEvent.CLICK, tellMe);
addChild(term);
textfields.push(term);
suggested.push(suggestions[j]);
term.text = suggestions[j];
}
}
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 = 0x4C311D;
}
if(e.keyCode == Keyboard.UP && currentSelection > 0)
{
currentSelection--;
textfields[currentSelection].textColor = 0x4C311D;
}
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;
}
} Any idea what could be the problem ?
... View more