3
我正在構建一個小型的基於Flash的語言翻譯器。一旦用戶在文本字段中輸入單詞或短語,我就會交叉引用XML父節點的子節點。結果將是返回到output_txt文本字段的該詞或短語的翻譯。錯誤#1067:將類型爲String的值隱式強制爲不相關的類型XML - AS3
問題是,Flash向我提供了有關字符串的值類型與無關類型XML有關的錯誤。爲什麼?有什麼建議麼?謝謝!
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);
}
var langObj:Object = new Object();
for (var entry:XML in myXML.children()) { //getting error #1067 on the XML========
langObj[entry.english.toString()]=entry.cockney.toString();
}
generate_mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent) {
English=textfield_txt.text;
if (langObj[textfield_txt.text]!=undefined) {
output_txt.text = myXML.cockney; //this is where the translation will appear. is this correct syntax?===============
} else {
trace("the key is not defined: " + textfield_txt.text);
}
}
看起來你不會看到這個標記爲答案,這太糟糕了,因爲它爲我工作。 – paul 2012-10-08 13:37:38