XML image node inside text search loop. AS2

Posted on 2009-12-22
Medium Priority
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)){
      return results;

ElementsToSearch = function(){
      var childElementsToSearch = [];
      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";


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(
      if (nodesWithQuery.length){
            results_txt.text = "NO RESULTS"+search_fields.query_txt.text+".";
            return (0);

Thanks for you help
Question by:mexican_d
  • 5
  • 4
LVL 39

Expert Comment

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?

Author Comment

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"?>

<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>

LVL 39

Expert Comment

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.

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

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.
LVL 39

Expert Comment

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.

LVL 39

Expert Comment

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.

Author Comment

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

Author Comment

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

Accepted Solution

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.


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.


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