?
Solved

XML image node inside text search loop. AS2

Posted on 2009-12-22
9
Medium Priority
?
709 Views
Last Modified: 2013-11-11
Hi Gurus and Genius people.
I´m trying to custom this XML Flash search that i found in kirupa.
It currently searches the XML for the input search data and it works fine displaying the rest of the text nodes inside the dynamic text field.But now i´d like to add an image field / node.
 I Belive i have to "use" the same display node function (loop?) to pull the image node into my wmpty MC, but i just don´t know how.

Currently i have in stage this:
1) Search box
2) Search button
3) Dynamic text field (html)
4) Empty movieclip

This is the code:

String.prototype.contains = function(searchString){
      return (this.indexOf(searchString) != -1);
}
Array.prototype.contains = function(searchValue){
      var i = this.length;
      while(i--) if (this[i] == searchValue) 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 = [];
            childElementsToSearch.push("boleto");
      return childElementsToSearch;
}

DisplayNodes = function(nodes, field_txt){
      field_txt.htmlText = "";
      var entry;
      for (var i=0; i<nodes.length; i++){
            entry = "";
            entry += "<b> TEXT1: </b>" + nodes[i].childNodes[0].firstChild.nodeValue + "<br>" ;
            entry += "<b> TEXT2: </b>" + nodes[i].childNodes[1].firstChild.nodeValue + "<br>";
            entry += "<b> TEXT3: </b>" + nodes[i].childNodes[2].firstChild.nodeValue + "<br>";
            entry += "<b> TEXT4: </b>" + nodes[i].childNodes[3].firstChild.nodeValue + "<br>";
            entry += "<b> TEXT5: </b>" + nodes[i].childNodes[4].firstChild.nodeValue+ "<br><br>";
            entry += "<b> <font color='#CC0000'> SOME MORE TEXT</font></b>"      
            field_txt.htmlText += entry;      
}      
}

var posts_xml = new XML();
posts_xml.ignoreWhite = true;
posts_xml.onLoad = function(success){
      if (success){
            search_fields._visible = true;
      }else results_txt.text = "ERROR MESSAGE";
}

posts_xml.load("ganadores.xml");

search_fields.search_btn.onRelease = function(){
      if (search_fields.query_txt.text.length < 6){
            results_txt.text = "CHECK YOUR INPUT";
            return (0);
      }

      var searchElements = ElementsToSearch();
      var nodesWithQuery =      SearchXML(
                                                posts_xml.firstChild.childNodes,
                                                search_fields.query_txt.text,
                                                searchElements
                                          );
      
      if (nodesWithQuery.length){
            DisplayNodes(
                  nodesWithQuery,
                  results_txt
            );
      }else{
            results_txt.text = "NO RESULTS"+search_fields.query_txt.text+".";
            return (0);
      }
}


Thanks for you help
0
Comment
Question by:mexican_d
  • 5
  • 4
9 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 26103330
hi, I don't understand what you mean with "But now i´d like to add an image field / node."

are you wanting to add a node in the xml (can you provide an xml snippet)
are are you wanting to add a filter to your search?
0
 

Author Comment

by:mexican_d
ID: 26103352
Hi..Blue genie...  thanks for answering...
Here is my XML attached (foto is the image node)

Now, What i want is to display along with all other (text) nodes (insde the dynamic text field in flash) an image inside a blank movie clip pulling it from the xml (ouside the dynamic text field).
I think done within the same "searching process"... do i make sense? not native english spoken...

<?xml version="1.0" encoding="utf-8"?>
<ganadores>

<ganador>
<boleto>120000</boleto>
<premio>1</premio>
<descripcion><![CDATA[Casa de lujo amueblada y decorada en Xalapa, Veracruz. Camioneta Chevrolet Captiva 2009 y Cheque por 60mil pesos]]></descripcion>
<nombre>Pablo Sergio Hernandez</nombre>
<ciudad>Coatepec, Veracruz</ciudad>
<foto><![CDATA[foto.jpg]]><foto>
</ganador>


</ganadores>
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 26103553
ok so basically if for example they search for boleto = 120000 you want to display whatever is in the foto node yes?

I cant get your xml search to work, it always returns no results.

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:mexican_d
ID: 26103590
Exactly.. the xml will have like more records to display according to the "boleto" input.
Here are the files so you can try them. AS2
I just learned the trick to add .tst after .sm extension files. so you just remove it to open. please.
gandores.zip
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 26104063
ok so basically if for example they search for boleto = 120000 you want to display whatever is in the foto node yes?

I cant get your xml search to work, it always returns no results.

0
 
LVL 39

Expert Comment

by:blue-genie
ID: 26105649
ooh sorry don't know what happened there with the duplicate post.

now i'm getting Lo sentimos, no se encontraron resultados para el boleto?


just tell me what i must type into the box to have it sucessfully return something so i can do the image loading test cause right now nothing is being returned.
0
 

Author Comment

by:mexican_d
ID: 26106917
Just type 120000,
it should load the xml only record. It works fine here
0
 

Author Comment

by:mexican_d
ID: 26110536
Hi, i´m still here. Very excited to see if you can come up with the solution. Have a nice day.
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 total points
ID: 26110788
ok why are you excited?

from  what i can make out from your search function, as soon as you find a match you break out of the loop so there will never be more than one result, is that correct?

if yes then you can just create a variable, if not you can create another array to store the images for each loop in your current search function.

okay so assume single result returned

you're already getting all the other data for when you display so just set your variable to the value as well


var imageToLoad:String = "";

in your DisplayNodes function

imageToLoad = nodes[i].childNodes[5].firstChild.nodeValue;
//if its an array just populate the array instead

then AFTER the for loop call a function to load the image and pass the string or array.

loadImage(imageToLoad);

then create the function

function loadImage(str:String):Void {      
      
      loadMovie(str, loaderClip);
}
//this function assumes you have an empty movieclip on the stage with instance name loaderClip.
this will load the image in the foto node into that clip.

if you're doing the array option you'll probably be better off generating the movieclips dynamically at run time.

good luck with it.



0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month4 days, 19 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question