views:

339

answers:

2
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); }

This is the code i am using to call a function calc in javascript, but i get the following error. What am i doing wrong here? (I modified the example on live docs.)

Error:

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

Void should be lower-case.

Like this:

void
Triptych
+1  A: 

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?

Christian Nunciato