Hello, I have a problem that has to be solved this week.
I have 1 input box.
A user will enter a feature into this box e.g “hair, fur, scales, teeth”
I then have this XML to search through.
<?xml version=“1.0”?>
<creature>
<category id=“mammal” has=“hairy_skin,mouth,warm_blood”>
<species id=“cat” has=“fur,tail,whiskers”>
<breed id=“tiger” has=“stripey_fur”/>
<breed id=“lion” has=“brown_fur,mane”/>
<breed id=“panther” has=“black_fur”/>
</species>
<species id=“dog” has=“hair,tail,wet_nose”>
<breed id=“labrador” has=“soft_hair”/>
</species>
<species id=“pig” has=“snout,trotters”/>
<species id=“cow” has=“nose,hooves”/>
</category>
<category id=“reptile” has=“scaly_skin,mouth,cold_blood”>
<species id=“lizard” has=“tail,legs”>
<breed id=“iguana” has=""/>
</species>
<species id=“snake” has=“tail,no_legs,forked_tongue”>
<breed id=“cobra” has=“hooded_head”>
<subbreed id=“greatcobra” has=“big_hood”/>
</breed>
</species>
</category>
<category id=“bird” has=“feathers,beak,wings,warm_blood” />
<category id=“fish” has=“scales,mouth,cold_blood”>
<species id=“mullet” has=“thick_lips”/>
<species id=“pike” has=“sharp_teeth”/>
</category>
</creature>
If for example a user enters “Scales”
the results need to display “fish has scales”
I have this piece of AS here that works. However it works from a different XML file.
is there any way in which this action script could be altered to search through the XML above?
[AS]
_global.creaturesObjects = [];
myXml = new XML();
myXml.ignoreWhite = true;
myXml.onLoad = parseMe;
myXml.Load(“creatures.xml”);
function parseMe(){
trace(“ParseMe” + this);
var creatures = this.firstChild.childNodes;
trace(creatures);
for (i=1;i<creatures.length;i++){
//trace(creatures*.nodeName);
obj = new Object();
obj.name = creatures*.nodeName;
obj.isa = creatures*.attributes.isa;
obj.has = creatures*.attributes.has.split(",");
//var obj = creatures*.attributes;
creaturesObjects.push(obj);
}
}
function has(strHas){
trace("has called: " + strHas);
//loop through animals
for(i in _global.creaturesObjects){
//loop through has properties
for(j in _global.creaturesObjects*.has){
//trace(_global.creaturesObjects*.name);
if(strHas == _global.creaturesObjects*.has[j]){
//trace(“found”);
_root.txt_answer.text = _root.txt_answer.text + "
" +
_global.creaturesObjects*.name + " has " + strHas;
}
}
}
}
[/AS]
with this on the button to submit the user input
[AS]
//this code goes on the button
on(Release) {
arrhas = new Array();
trace(_root.txt_has.text);
arrhas = txt_has.text.split(",");
for (i in arrhas) {
has(_root.arrhas*);
}
}
[/AS]
i really need some help with this, any help is much appreciated
thanks