Search XML file from selection in List Box and return result

  • BillyBoy
  • Newbie
  • Newbie
  • BillyBoy
  • Posts: 9

Post 3+ Months Ago

ave a Flash MX 2004 question...

I want to have a list box that lists words/phrases then have the selected item search a XML file and return matches in a dynamic text filed.

I created a simple array of phrases /words to be used in a glossary. I created a list box. This works fine. I also made a XML file to list the contents, since over time it will expand a good deal. I can't seem to find a way to pass the selected item from the list box to search the XML.

If I use

on (release) {
trace(myListBox_lb.getSelectedItem());
}

in a event handler for a button I get the selected phrase/word, but I need to pass the selected word so that's what is searched for any returned.

Any help greatly appreciated. TIA.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

When you say that the glossery will expand a great deal, how big are you talking ?
Keep in mind that you shouldn't have more than 400 (300 even) items combined in all boxes in one frame at any given time.

Where are you wanting to search the XML ? Inside flash (loading entire XML file, then searching), or pass the selection to an ASP, PHP, ect.. script that will search & return the results ?

If this file will contain a huge amount of entries you may want to do the latter.

If your looking to search the XML within flash then you need to pass the selectedItems .label or .data to your search function (or have the function grab it itself)

Example, (assuming XML is loaded & glossery has been assigned to labels of listBox)
Code: [ Select ]
/* lookIn is an array holding info parsed from XML */
on(release){
   resultHTML = ""; //declare & zero build string for textBox
   toFind = myListBox_lb.getSelectedItem().label; //or .data for data associated with item
   for(i=0; i < lookIn.length; i++){
     if(lookIn[i].indexOf(toFind) != -1){
        resultHTML += ("<b>Match</b> " + i + "<br>" + lookIn[i] + "<br>");
   }
   resultTextBox.htmlText = resultHTML;
   delete resultHTML;
}
  1. /* lookIn is an array holding info parsed from XML */
  2. on(release){
  3.    resultHTML = ""; //declare & zero build string for textBox
  4.    toFind = myListBox_lb.getSelectedItem().label; //or .data for data associated with item
  5.    for(i=0; i < lookIn.length; i++){
  6.      if(lookIn[i].indexOf(toFind) != -1){
  7.         resultHTML += ("<b>Match</b> " + i + "<br>" + lookIn[i] + "<br>");
  8.    }
  9.    resultTextBox.htmlText = resultHTML;
  10.    delete resultHTML;
  11. }

This is a generic example assuming a simple list of items to search through, then display results in a HTML enabled dynamic textBox.
  • BillyBoy
  • Newbie
  • Newbie
  • BillyBoy
  • Posts: 9

Post 3+ Months Ago

Thanks Joe! :D

I'm thinking maybe 300 or so entries tops. I just meant "expand greatly" from my viewpoint, just tried a few entries to test so far. Thanks for the code, I was forgetting about the .label part!

I'll give it a try tomorrow.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 21 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.