外部接口错误

发布于 2024-07-11 20:25:20 字数 571 浏览 4 评论 0原文

这是我用来在 javascript 中调用函数 calc 的代码:

import flash.external.ExternalInterface;

ExternalInterface.addCallback("asFunc", this, asFunc); 

function asFunc(str:String):Void {
    out.text = "JS > Hello " + str;
}

send_btn.addEventListener(MouseEvent.CLICK, clickListener);

function clickListener(eventObj:Object):Void {
    trace("click > " + mean.text);
    ExternalInterface.call("calc", mean.text);
}

但出现以下错误:

1046:未找到类型或不是编译时常量:Void。

我在这里做错了什么? (我修改了实时文档中的示例。)

This is the code I am using to call a function calc in javascript:

import flash.external.ExternalInterface;

ExternalInterface.addCallback("asFunc", this, asFunc); 

function asFunc(str:String):Void {
    out.text = "JS > Hello " + str;
}

send_btn.addEventListener(MouseEvent.CLICK, clickListener);

function clickListener(eventObj:Object):Void {
    trace("click > " + mean.text);
    ExternalInterface.call("calc", mean.text);
}

but I get the following error:

1046: Type was not found or was not a compile-time constant: Void.

What am I doing wrong here? (I modified the example on live docs.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

鹿童谣 2024-07-18 20:25:20

void 应该是小写。

像这样:

void

Void should be lower-case.

Like this:

void
坏尐絯℡ 2024-07-18 20:25:20

看起来(根据你的错误)你在这里有几个问题:

  1. ExternalInterface在AS3中采用两个参数,而不是三个
  2. “Void”在AS3中应该是“void”

所以假设你的JavaScript代码是这样的:

function myJSFunction()
{
    myFlashObject.asFunc("Hello!");
}

function calc(s)
{
    // ...
}

...你相应的ActionScript 3 代码应该看起来更像这样:

import flash.external.ExternalInterface; 

function myInitializationHandler():void
{   
    ExternalInterface.addCallback("asFunc", asFunc); 
    myFlexButton.addEventListener(MouseEvent.CLICK, clickListener); 
}

function asFunc(str:String):void 
{ 
    //... 
}

function clickListener(event:MouseEvent):void 
{ 
    // ...
    ExternalInterface.call("calc", myFlexTextInput.text); 
}

有意义吗?

Looks (by your error) like you have a couple of problems here:

  1. ExternalInterface takes two arguments in AS3, not three
  2. "Void" should be "void" in AS3

So assuming your JavaScript code were something like this:

function myJSFunction()
{
    myFlashObject.asFunc("Hello!");
}

function calc(s)
{
    // ...
}

... your corresponding ActionScript 3 code should look something more like this:

import flash.external.ExternalInterface; 

function myInitializationHandler():void
{   
    ExternalInterface.addCallback("asFunc", asFunc); 
    myFlexButton.addEventListener(MouseEvent.CLICK, clickListener); 
}

function asFunc(str:String):void 
{ 
    //... 
}

function clickListener(event:MouseEvent):void 
{ 
    // ...
    ExternalInterface.call("calc", myFlexTextInput.text); 
}

Make sense?

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