0

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.)

4

2 に答える 2

1

void は小文字にする必要があります。

このような:

void
于 2009-01-12T20:24:02.830 に答える
1

ここにいくつかの問題があるように(あなたのエラーによって)見えます:

  1. AS3 では、ExternalInterface は 3 つではなく 2 つの引数を取ります
  2. AS3 では「無効」を「無効」にする必要があります

したがって、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); 
}

わかる?

于 2009-01-12T20:36:18.857 に答える