Im a total noob on actionscript, NEVER used it, but Im compiling a Unity project to flash, and for doing browser<-> javascript communication I nned to make a hackish thing providing a class on .as code..
The unity is acusing it doesnt know the type string:
“Type was not found or was not a compile-time constant: string.”
Heres my code, note I dont have even a flash compiler, Im using notepad++, so Im on a minefield, dont know the language and cant debug it.
import flash.external.ExternalInterface;
import flash.system.Security;
import global.SCORMInsideActionScriptFunctions;
public class BrowserCommunicator
{
public static function callFromJavascript() : void
{
trace("Javascript successfully called ActionScript function.");
}
// callback to register:
public static function GetSessionTime() : string
{
return SCORMInsideActionScriptFunctions.GetSessionTime()
}
//Sets up an ExternalInterface callback and calls a Javascript function.
public static function TestCommunication() : void
{
if (ExternalInterface.available)
{
try
{
ExternalInterface.addCallback("callFromJavascript", callFromJavascript);
// mine:
ExternalInterface.addCallback("GetSessionTime", GetSessionTime);
}
catch (error:SecurityError)
{
trace("A SecurityError occurred: " + error.message);
}
catch (error:Error)
{
trace("An Error occurred: " + error.message);
}
ExternalInterface.call('calledFromActionScript');
}
else
{
trace("External interface not available");
}
}
public static function FlushData_ServerToCache() : void
{
if (ExternalInterface.available)
{
// calls the java function here:
ExternalInterface.call('flushData');
}
else
{
trace("External interface not available");
}
}
public static function SubmitData_CacheToServer() : void
{
if (ExternalInterface.available)
{
ExternalInterface.call('submitData');
}
else
{
trace("External interface not available");
}
}
public static function SetData_AppToCache( field : string, data : string) : void
{
if (ExternalInterface.available)
{
ExternalInterface.call('setData', field, data);
}
else
{
trace("External interface not available");
}
}
public static function GetData_CacheToApp( field : string ) : string
{
if (ExternalInterface.available)
{
return ExternalInterface.call('getData', field);
}
else
{
trace("External interface not available");
return "";
}
}
}
}
Just write String instead of string 🙂