2

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.

1
  • add console.log("called"); before args = String(args); What will happen? Or try ExternalInterface.call('player_DoFSCommand("CC_ClosePlayer", "test")');
    – Smolniy
    Commented Mar 5, 2013 at 16:49

1 Answer 1

7

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...");
1
  • I assumed allowScriptAccess was set to true because the parent SWF calls JavaScript functions... however it was using the outdated swLiveConnect. I also used your function syntax - followed a bad tutorial on ExternalInterface Commented Mar 6, 2013 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.