5 Replies Latest reply on May 26, 2010 7:41 AM by kglad

    AS2 Search xml - need progress timer of some sort

    mimcc

      greetings!

       

      I have followed Kirupa's XML Search engine here: http://www.kirupa.com/web/xml/examples/searchbestof.htm

       

      My XML, however, is quite large. What I need is to initiate a "progress bar" or "timer" or... er... something that would show on the screen when the person clicks "Search". It only takes a few seconds but I think that some sort of graphic would be needed. I cannot find the correct terms to search with google or bing so, here I am!

       

      I have a button called "search_btn" inside of an MC called "search_fields" that, when clicked, I would like to have a graphic showing some progress like a clock hand or something that would disappear when the dynamic text box (results_txt) is updated with the results of the search.

       

      Any advice is greatly appreciated!

       

      Button onRelease AS:

       

      on (release) {
      search_fields.search_btn.onRelease = function(){
      if (search_fields.query_txt.text.length < 3){
      results_txt.text = "Please use a search term with 3 or more characters.";
      return (0);
      }
       
      var searchElements = ElementsToSearch();
       
      var nodesWithQuery = SearchXML(
      search_xml.firstChild.childNodes,
      search_fields.query_txt.text,
      searchElements
      );
       
      if (nodesWithQuery.length){
      DisplayNodes(
      nodesWithQuery,
      results_txt
      );
      }else{
      results_txt.text = "No results for "+search_fields.query_txt.text+".";
      return (0);
      }
       
      HighlightOccurences(
      search_fields.query_txt.text,
      results_txt,
      search_highlight
      );
      }
      }

      Actions on Frame 1:

       

      var search_xml = new XML();
      search_xml.ignoreWhite = true;
      search_xml.onLoad = function(success){
      if (success){
      search_fields._visible = true;
      }else results_txt.text = "Error loading XML";
      }
      search_fields._visible = false;
      search_xml.load("titles_temporary.xml");


      String.prototype.contains = function(searchString){
      return (this.toLowerCase().indexOf(searchString.toLowerCase()) != -1);
      }
      Array.prototype.contains = function(searchValue){
      var i = this.length;
      while(i--) if (this[i].toLowerCase() == searchValue.toLowerCase()) return true;
      return false;
      }

      SearchXML = function(nodes, query, useChildElements){
      var results = [];
      for (var i=0; i<nodes.length; i++){
        for (var j=0; j<nodes[i].childNodes.length; j++){
         currNode = nodes[i].childNodes[j];
         if (useChildElements.contains(currNode.nodeName)){
          if (currNode.firstChild.nodeValue.contains(query)){
           results.push(nodes[i]);
           break;
          }
         }
        }
      }
      return results;
      }

      ElementsToSearch = function(){
      var childElementsToSearch = [];
      if (search_fields.title_check.checked){
        childElementsToSearch.push("title_1");
      }
      if (search_fields.author_check.checked){
        childElementsToSearch.push("title_2");
      }
      if (search_fields.message_check.checked){
        childElementsToSearch.push("number");
      }
      return childElementsToSearch;
      }

      DisplayNodes = function(nodes, field_txt){
      field_txt.htmlText = "";
      var entry;
      var separator = "<br>____________________________________________________________________________________ _<br><br>";
      for (var i=0; i<nodes.length; i++){
        entry = "";
        entry += "<b>"+ nodes[i].childNodes[0].firstChild.nodeValue +"</b>";
        entry += "<br>" +"<b>"+ nodes[i].childNodes[1].firstChild.nodeValue +"</b>";
        entry += "<br>" +"<b>"+ nodes[i].childNodes[2].firstChild.nodeValue +"</b>";
        entry += "<br>" + "File Number: " + "<b>"+ nodes[i].childNodes[3].firstChild.nodeValue +"</b>";
        if (nodes[i].attributes.url.length){
         entry += "<br><a href='" + nodes[i].attributes.url;
         entry += "'><font color='#0000FF'>Read more...</font></a>";
        }
        field_txt.htmlText += entry + separator;
      }
      }
      search_highlight = new TextFormat();
      search_highlight.color = 0xFF0000;
      search_highlight.italic = true;

      HighlightOccurences = function(str, field_txt, format){
      if (!str.length) return (0);
      var start = field_txt.text.indexOf(str);
      var end = start + str.length;
      while (start != -1){
        field_txt.setTextFormat(start, end, search_highlight);
        start = field_txt.text.indexOf(str, end);
        end = start + str.length;
      }
      }
      search_fields.title_check.title_txt.text = "English";
      search_fields.author_check.title_txt.text = "French";
      search_fields.message_check.title_txt.text = "Table Number";

      search_fields.search_btn.onRelease = function(){
      if (search_fields.query_txt.text.length < 3){
        results_txt.text = "Please use a search term with 3 or more characters.";
        return (0);
      }

      var searchElements = ElementsToSearch();
      var nodesWithQuery = SearchXML(
              search_xml.firstChild.childNodes,
              search_fields.query_txt.text,
              searchElements
             );

      if (nodesWithQuery.length){
        DisplayNodes(
         nodesWithQuery,
         results_txt
        );
      }else{
        results_txt.text = "No results for "+search_fields.query_txt.text+".";
        return (0);
      }

      HighlightOccurences(
        search_fields.query_txt.text,
        results_txt,
        search_highlight
      );

      scrollbar.setScroll(0);
      }
      scrollbar.setTarget(results_txt);
      stop();