Actionscript 3 中的外部接口无法正确传递西里尔字母
我有一个Flash(Flex ActionScript项目),它必须通过外部接口将数据传递给Cyrrilic中的JavaScript。然而,数据在 javascript 端出现了?而不是真正的西里尔字母,
如何解决这个问题,使其显示为西里尔字母?
var url:URLRequest = new URLRequest("javascript:allInfo('ядене'); void(0);");
navigateToURL(url, "_self");
这是 JS 函数
function allInfo(info){
alert(info);
}
谁能建议如何解决这个问题?
I have a flash (flex actionscript project) that has to pass data to javascript in cyrrilic through externalinterface. However, data turns out at the javascript end in ????? instead of real cyrillic letters
how can this be fixed so it shows up as cyrillic?
var url:URLRequest = new URLRequest("javascript:allInfo('ядене'); void(0);");
navigateToURL(url, "_self");
And here is the JS function
function allInfo(info){
alert(info);
}
Can anyone suggest how to resolve the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这很可能是编译时编码的问题。我测试了你提供的代码,它运行得很好。确保您的编译器使用正确的编码解释您的文件。
如果你想测试一下,你可以简单地做一个
trace('ядене')
,如果在Flash的控制台日志中,你看到奇怪的字符,那就是编译时的编码。至于如何修复,我对编译器的了解不足以为您指明正确的方向。这也可能是您将数据传输到的页面的编码问题。如果您的 Flash 文件是以 UTF-8 编译的,并且您的 html 页面使用其他编码,则可以解释您的问题。在这种情况下,只需确保 html 和 flash 文件的编码相同即可。
最后,要解决大多数ExternalInterface 错误,您可以采取的措施是在Flash 端
转义
数据并在Javascript 端unescape
数据。示例:Flash:
Javascript:
It's most probably an issue with the encoding at the compilation time. I tested the code you gave and it worked perfectly. Make sure your compiler interpret your file with the proper encoding.
If you want to test it, you can simple do a
trace('ядене')
, if in the console log of Flash, you see wierd character, it's the encoding at compilation time. As to how to fix, I don't know the compiler enough to point you in the right direction.It could also be a problem with the encoding of the page you are transfering data to. If your Flash file is compiled in UTF-8 and your html page is served with an other encoding that could explain your problem. In that case, just make sure the encoding of the html and your flash file is the same.
In last resort, what you can do to go around most ExternalInterface bug is to
escape
the data on the Flash side andunescape
it on the Javascript side. Example :Flash :
Javascript :
对我来说效果很好,正如你所拥有的那样。使用针对在 Firefox 4 中运行的 Flash Player 11 的 Flex 4.5 SDK 在 Flash Builder 4.5 中编译。如果您仍然遇到问题,请发布您的测试 swf 和完整的 HTML 页面。
Works fine for me exactly as you have it. Compiled in Flash Builder 4.5 using the Flex 4.5 SDK targeting Flash Player 11 running in Firefox 4. Post your test swf and full HTML page if you're still having problems.
在发送之前尝试将字符串转换为 UTF-8。
Try converting the string to UTF-8 before sending it.