okay, here is the problem… i have a text file and i have it in xml format as well, in it is a list of 55 companies that i want to load into my movie and have them stored as an array that i can search. I am having a hard time making it happen, though… i am new to using xml and the format is just simply:
<companies>
<name> Akai<name/>
<name> Altec Lansing <name/>
<name> Audio Centron <name/>
<name> Ampeg <name/>
<name> Allen and Heath <name/>
<name> Biamp Systems <name/>
<name> Cerwin Vega <name/>
<name> Community <name/>
<name> Crest Audio <name/>
<name> Crate <name/>
<name> DBX <name/>
<name> Digitech <name/>
<name> DOD <name/>
<name> Dynacord <name/>
<name> Electrovoice <name/>
<name> Eden Electronics <name/>
<name> EAW <name/>
<name> Fatar <name/>
<name> Fender <name/>
</companies>
somthing like that… and the text file is just the variable companies=“blah, blah and blah”
any help would be tremendously appreciated!
system
July 31, 2003, 4:33pm
2
this is how the xml file should look like
<?xml version="1.0"?>
<companies>
<name>Akai</name>
<name>Altec Lansing</name>
<name>Audio Centron</name>
<name>Ampeg</name>
<name>Allen and Heath</name>
<name>Biamp Systems</name>
<name>Cerwin Vega</name>
<name>Community</name>
<name>Crest Audio</name>
<name>Crate</name>
<name>DBX</name>
<name>Digitech</name>
<name>DOD</name>
<name>Dynacord</name>
<name>Electrovoice</name>
<name>Eden Electronics</name>
<name>EAW</name>
<name>Fatar</name>
<name>Fender</name>
</companies>
and this AS parses it into an array called ‘companies’
myxml = new XML()
myxml.ignoreWhite = 1
myxml.onLoad = function() {
this = this.firstChild.childNodes
Companies = []
for(i=0; i<this.length; i++) Companies* = this*.firstChild
trace(Companies)
}
myxml.load("companies.xml")
system
July 31, 2003, 6:53pm
3
the only problem is that the trace only outputs the first company “akai”… i am looking at how to fix, though.
system
July 31, 2003, 7:01pm
4
if you just have Companies* = this* you get the xml output to a string of <name> blahdeeblah </name>… so now how do you split it up?
system
July 31, 2003, 8:42pm
5
i don’t get you. What I posted worked fine. Don’t use this*, you should use this*.firstChild (and that’s how i did it in my script… )
system
July 31, 2003, 8:59pm
6
your original code only gave an output of the first company - akai. How do you get it to output all the “children” of <companies>???
system
August 1, 2003, 2:37pm
7
actually, brewer… his code is correct and trace shows all the companies listed. Are you trying to incorporate this into a textfield?
btw… if you’re not getting all of the children…hehe… check your xml file… make sure you changed all of your “/” to the correct location.
system
August 1, 2003, 4:19pm
8
you were correct… shame on me for not double checking my xml. I could not figure out why it wasn’t displaying… duh.
Yes i am eventually trying to display it in a text field. The story is i have an input field that people can enter in a companies name to see if this company does warranty repair work on that companies gear. I wanted to avoid having to search a database and so i thought i could bring in all the names via and xml doc, turn it into an array and search thru that. I actually got all the way to the array, but searching is turning up the index of the array, not the content. If you have any suggestions, please let me know.
system
August 1, 2003, 5:13pm
9
lol, i posted the correct xml file for you, but you used the older one…
system
August 1, 2003, 5:21pm
10
arrayToBeSearched = ["Kirupa", "lostinbeta", "senocular", "ahmed"];
function searchArray(theArray, searchstring){
var outputArray = [];
for(var i = 0; i<theArray.length;i++){
if(theArray*.toLowerCase().indexOf(searchString.toLowerCase()) != "-1"){
outputArray.push(theArray*);
}
}
return outputArray;
}
//returns another array of matched elements.
trace(searchArray(arrayToBeSearched, "LOS")) //outputs 'lostinbeta'
system
August 1, 2003, 5:33pm
11
that’s nice, why not make it a prototype?
system
August 1, 2003, 5:36pm
12
Yeah, I probably will… that was just a 5min example though to help him get the idea really though.
system
August 1, 2003, 5:38pm
13
Done(-:
Array.prototype.searchArray = function(searchString){
var outputArray = [];
for(var i = 0; i<this.length;i++){
if(this*.toLowerCase().indexOf(searchString.toLowerCase()) != "-1"){
outputArray.push(this*);
}
}
return outputArray;
}
system
August 1, 2003, 6:57pm
14
so here’s what i am trying and my brain must be fried cos i am going nowhere…
search_btn.onPress = function() {
Companies.searchArray(input);
trace(input);
if(input == outputArray){
display = outputArray;
}
}
input being the variable from the input_txt…
gonna keep at it, though.
system
August 1, 2003, 7:51pm
15
The function I wrote returns an array containing the results of the search, so for the code you wrote, you would need to do something like this:
search_btn.onPress = function() {
var searchResults = Companies.searchArray(input);
trace(input);
display = searchResults;
}
You can use the as tags for code formatting as well.
[as] code goes here(without asterisks)[ /as]
system
August 1, 2003, 8:20pm
16
okay, that makes perfect sense, but when i tried it, display displayed all of the companies, not just the one i entered into the search…
this is almost funny…
system
August 1, 2003, 10:00pm
17
Do you have any more code, or could you post your .fla?
system
August 2, 2003, 7:10am
18
okay, here it is…
myxml = new XML();
myxml.ignoreWhite = true;
myxml.onLoad = function() {
this = this.firstChild.childNodes;
Companies = [];
for (i=0; i<this.length; i++) {
Companies* = this*.firstChild;
}
//trace(Companies);
};
myxml.load("warranty.xml");
//search
Array.prototype.searchArray = function(searchString) {
var outputArray = [];
for (var i = 0; i<this.length; i++) {
if (this*.toLowerCase().indexOf(searchString.toLowerCase()) != " -1 ") {
outputArray.push(this*);
}
}
return outputArray;
};
search_btn.onPress = function() {
input = "";
var searchResults = Companies.searchArray(input);
trace(input);
display = searchResults;
};
that is it and the xml doc is the same as the one before…
system
August 11, 2003, 9:49pm
19
is there anyone out there that can help with why this code is spitting out all the companies in the array instead of just one???
system
August 12, 2003, 12:23pm
20
in the code above, in my array search prototype, the -1 has two spaces around it. Remove them, or take it out of a string.
Array.prototype.searchArray = function(searchString) {
var outputArray = [];
for (var i = 0; i<this.length; i++) {
if (this*.toLowerCase().indexOf(searchString.toLowerCase()) != -1) {
outputArray.push(this*);
}
}
return outputArray;
};