Trouble cross-referencing two XML child nodes in AS3
Posted
by Dwayne
on Stack Overflow
See other posts from Stack Overflow
or by Dwayne
Published on 2010-03-07T07:40:14Z
Indexed on
2010/03/08
16:36 UTC
Read the original article
Hit count: 412
I am building a mini language translator out of XML nodes and Actionscript 3. I have my XML ready. It contains a series of nodes with two children in them. Here is a sample:
<translations>
<entry>
<english>man</english>
<cockney>geeza</cockney>
</entry>
<entry>
<english>woman</english>
<cockney>lily</cockney>
</entry>
</translations>
The AS3 part consist of one input box named "textfield_txt" where the English word will be typed in. An output text field for the translation called "cockney_txt". Finally, one button to execute the translation called "generate_mc".
The idea is to have actionscript look through the XML for key English words after the user types it in the "textfield", cross-freferences the children then returns the Cockney translation as a value.
The trouble is, when I test it I get no response or error messages- it's completely silent. I'm not sure what I'm doing wrong.
At present, I have setup a conditional statement to tell me whether the function works or not. The result is, no it's not! Here's the code below. I hope someone can help.
Cheers!
generate_mc.buttonMode=true;
var English:String;
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("Language.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
}
generate_mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent) {
English = textfield.text;
cockney_txt.text = myXML.translations.entry.cockney;
if(textfield.text.toLowerCase() == myXML.translations.entry.english.toLowerCase){ //return myXML.translations.entry.cockney; trace("success"); }else{ trace("try again!"); // ***I get this as a result }
}
© Stack Overflow or respective owner