Skip to main content
Participant
May 25, 2010
Question

AS2 Search xml - need progress timer of some sort

  • May 25, 2010
  • 1 reply
  • 1311 views

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.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.childNodes.length; j++){
   currNode = nodes.childNodes;
   if (useChildElements.contains(currNode.nodeName)){
    if (currNode.firstChild.nodeValue.contains(query)){
     results.push(nodes);
     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.childNodes[0].firstChild.nodeValue +"</b>";
  entry += "<br>" +"<b>"+ nodes.childNodes[1].firstChild.nodeValue +"</b>";
  entry += "<br>" +"<b>"+ nodes.childNodes[2].firstChild.nodeValue +"</b>";
  entry += "<br>" + "File Number: " + "<b>"+ nodes.childNodes[3].firstChild.nodeValue +"</b>";
  if (nodes.attributes.url.length){
   entry += "<br><a href='" + nodes.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();

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 25, 2010

look up:  flash preloader animation.

mimccAuthor
Participant
May 26, 2010

Thanks... I would still appreciate some help with my AS but I appreciate your help.

I know see that I should build the search results as an MC that doesnt show until the search is replaced. The onclick event will call the preloader timer swf that will be replaced with the dynamic text box with the results....

is that what you are saying?

kglad
Community Expert
Community Expert
May 26, 2010

i was suggesting, while your app is processing the search, you display a preloader animation that indicates something  is happening.  that way users know everything is proceeding as expecting.

p.s.  that's more than my limit for code checking in a forum.