I am attempting to ExternalInterface.call()
from inside my SWF.
Note the call comes from inside a SWF I have embedded into another SWF (the _root
SWF I have no control over).
Here is my JavaScript:
function player_DoFSCommand(command, args)
{
args = String(args);
command = String(command);
var arrArgs = args.split(g_strDelim);
switch (command)
{
case "CC_ClosePlayer":
console.log("yo");
break;
default:
// alert(command);
break;
}
}
Here is my AS2 code:
import flash.external.ExternalInterface;
var quiz = _root;
quiz.g_mcFrame.mcFinish.swapDepths(quiz.getNextHighestDepth());
quiz.g_mcFrame.mcFinish._visible = false;
quiz.oSlide.m_oInteraction.m_oVariableMgr.m_arrBoolResumeData = false;
var arrVars:Object = quiz.oSlide.m_oActionHandler.m_oFrame.m_oVariableMgr.m_arrVariables;
var args:Array = [
arrVars[2].m_nNumber, // Points awarded
arrVars[3].m_nNumber, // Max points
arrVars[5].m_nNumber, // Pass percentage
arrVars[6].m_nNumber, // Pass points
arrVars[7].m_nNumber, // Score percent
arrVars[10].m_strString // Result
];
ExternalInterface.call('player_DoFSCommand("CC_ClosePlayer", args)');
ExternalInterface.call('console.log("hello")');
The problem is ExternalInterface.call('player_DoFSCommand("CC_ClosePlayer", args)')
doesn't work, or atleast "yo" doesn't appear in the console as expected.
The script is definitely loaded by the time the ExternalInterface is called. The second call works and "hello" appears in the console, however the first function doesn't fire.
I can verify the function works by typing directly into the console player_DoFSCommand("CC_ClosePlayer", args)
and it logs successfully.
Can you verify that allowScriptAccess is set to true in the embed code?
Try this:
var isAvailable:Boolean = ExternalInterface.available;
trace(isAvailable);
You also want to use ExternalInterface like this, with your arguments passed as the second variable:
ExternalInterface.call("player_DoFSCommand",args);
or
ExternalInterface.call("console.log","testing...");