1 Reply Latest reply on Jan 11, 2012 2:55 AM by JR_Boulay

    Building a googlelike search

    abcNocturn

      Hi,

      one last problem I hope -.- .

      I have a textfield and a listbox.

       

      I'm trying to build a google like searchfield and it works as intended. But it takes forever for the script to load when I insert a text.

       

      Textbox -> Format -> keyinsert :

      var f_text = getField("test") ;
      var f_list = getField("listbox") ;
      
      var textarray = new Array () ;
      textarray[0] = new Object();
      textarray[0]["text"] = "Ozonschicht";
      textarray[0]["zuordnung"] = "1";
      textarray[1] = new Object();
      textarray[1]["text"] = "Ozonloch";
      textarray[1]["zuordnung"] = "1";
      textarray[2] = new Object();
      textarray[2]["text"] = "Ochsenzoll";
      textarray[2]["zuordnung"] = "2";
      
      var regex = new RegExp (event.value) ;
      
      var usearray = new Array () ;
      
      for (var i = 0; i < textarray.length; i++) {
          if ( regex.test ( textarray[i]["text"] ) ) {
              usearray.push ( textarray[i]["text"] ) ;
          }
      }
      if ( usearray.length > 0 ) {
          f_list.clearItems() ;
          f_list.setItems(usearray);
          f_list.display = display.visible ;
      } else {
          f_list.clearItems() ;
          f_list.display = display.hidden ;
      }
      

       

      Listbox -> onChange :

      var f_text = getField("test") ;
      var f_list = getField("listbox") ;
      f_text.value = event.value ;
      f_list.display = display.hidden ;
      

       

      Why does this script loads for some seconds ?