XML image node inside text search loop. AS2

Posted on 2009-12-22
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
    LVL 39

    Expert Comment

    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

    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

    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.


    Author Comment

    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

    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

    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

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

    Author Comment

    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

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now