错误 #1067 的问题:将 String 类型的值隐式强制为不相关的 XML 类型 - AS3

发布于 2024-08-24 11:49:59 字数 1018 浏览 5 评论 0原文

我正在构建一个基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼痛 2024-08-31 11:49:59

您必须将 for (... in myXML.children()) 更改为 for each (... in myXML.children())孩子())。使用 for (... in ...)for every (... in ...) 之间存在细微差别,但我不太确定他们就是这样。在迭代字典/对象时,循环的行为也有所不同:前者给出键,而后者给出值。

You have to change for (... in myXML.children()) to for each (... in myXML.children()). There is a subtle difference between using for (... in ...) and for 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文