Actionscript 3 中的外部接口无法正确传递西里尔字母

发布于 2024-11-01 22:33:57 字数 396 浏览 0 评论 0原文

我有一个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 技术交流群。

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

发布评论

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

评论(3

明天过后 2024-11-08 22:33:57

这很可能是编译时编码的问题。我测试了你提供的代码,它运行得很好。确保您的编译器使用正确的编码解释您的文件。

如果你想测试一下,你可以简单地做一个trace('ядене'),如果在Flash的控制台日志中,你看到奇怪的字符,那就是编译时的编码。至于如何修复,我对编译器的了解不足以为您指明正确的方向。

这也可能是您将数据传输到的页面的编码问题。如果您的 Flash 文件是以 UTF-8 编译的,并且您的 html 页面使用其他编码,则可以解释您的问题。在这种情况下,只需确保 html 和 flash 文件的编码相同即可。

最后,要解决大多数ExternalInterface 错误,您可以采取的措施是在Flash 端转义 数据并在Javascript 端unescape 数据。示例:

Flash:

var url:URLRequest = new URLRequest("javascript:allInfo('" + escape("ядене")  + "'); void(0);");
flash.net.navigateToURL(url, "_self");

Javascript:

function allInfo(txt) {
    alert("Test : " + unescape(txt));
}

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 and unescape it on the Javascript side. Example :

Flash :

var url:URLRequest = new URLRequest("javascript:allInfo('" + escape("ядене")  + "'); void(0);");
flash.net.navigateToURL(url, "_self");

Javascript :

function allInfo(txt) {
    alert("Test : " + unescape(txt));
}
热情消退 2024-11-08 22:33:57

对我来说效果很好,正如你所拥有的那样。使用针对在 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.

望笑 2024-11-08 22:33:57

在发送之前尝试将字符串转换为 UTF-8。

// These may seem backwards, just remember it's a conversion situation.
function decode_utf8( s:String ):String {
  return decodeURIComponent( escape( s ) );
}

function encode_utf8( s:String ):String {
  return unescape( encodeURIComponent( s ) );
}

Try converting the string to UTF-8 before sending it.

// These may seem backwards, just remember it's a conversion situation.
function decode_utf8( s:String ):String {
  return decodeURIComponent( escape( s ) );
}

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