actionscript 3 - search in a textFiedl, a specific word -
i've got, in as3 code, textfield load sentences database (each sentences title.
how can search bar textfield. when user type word "computer" (for exemple), it'll search in every sentences word "computer".
here's current code :
function createlistitem(index:int, item:object):void { var listitem:textfield = new textfield(); var myformat:textformat = new textformat(); myformat.size = 25 myformat.color = 0x000000; myformat.font = "mohave"; listitem.defaulttextformat = myformat; listitem.text = item.title; listitem.x = 10; listitem.y = 140+ index * 40; listitem.width = 160; feedbacktext.text = "createlistitem" +item.title; listitem.addeventlistener(mouseevent.click, function(e:mouseevent):void { showdetails(item); }); list.addchild(listitem); }
and displays list this:
"i sell computer" "i sell desk" "computer , apple"
(and know if can search bar in order display sentences specific word).
thx help,
first convert list array
var str: string = "first sentence. second sentence. third sentence. fourth sentence"; var arr: array = str.split(".");/// split string array items function searching(val: string): string { var collectedstring: string = ""; (var i: int = 0; < arr.length; i++) { if (arr[i].search(val) > -1) { collectedstring += arr[i].tostring()+"."; } } return collectedstring; } trace(searching("second")); /// input key word trace( searching("sentence")); /// key word
Comments
Post a Comment