错误 #1067 的问题:将 String 类型的值隐式强制为不相关的 XML 类型 - AS3
我正在构建一个基于 Flash 的小型语言翻译器。一旦用户在文本字段中输入单词或短语,我就会交叉引用 XML 父节点的子节点。结果将是返回到 output_txt 文本字段的该单词或短语的翻译。
问题是,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);
}
}
I'm building a small flash-based language translator. I am cross-referencing children of an XML parent node once the user types in a word or phrase into the text field. The result will be a translation of that word or phrase returned to the output_txt text field.
The problem is, Flash gives me this error regarding the value type of a String to an unrelated type XML. Why? Any suggestions? Thanks!
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将
for (... in myXML.children())
更改为for
each(... in myXML.children())孩子())
。使用for (... in ...)
和for every (... in ...)
之间存在细微差别,但我不太确定他们就是这样。在迭代字典/对象时,循环的行为也有所不同:前者给出键,而后者给出值。You have to change
for (... in myXML.children())
tofor
each(... in myXML.children())
. There is a subtle difference between usingfor (... in ...)
andfor each (... in ...)
, but I am not exactly sure which they are. The loops behave differently when iterating over dictionarys/object too: the former gives the keys, while the latter gives the values.