0

I want to call a JS function from within an object that is passed to flash.

JS code:

 <script>
    function initContext() {
        flashMovie.setContext(ctx);
    }

    var ctx = new Object();
    ctx.saySomething = function(msg) {
        alert(msg);
    }   
</script>

AS3 code:

if (ExternalInterface.available) {  
    ExternalInterface.addCallback("setContext", say);
    ExternalInterface.call("initContext");
}

So first AS3 calls JS initContext and JS initContext then calls setContext with an object. So far this works. I am stuck at how to call the function saySomething from the passed object:

private function say(context:Object) {
    ExternalInterface.call(???);
}

1 Answer 1

1

You can't execute the saySomething JavaScript function on the actual ctx object that you passed to ActionScript, since ActionScript can't execute JavaScript internally.

When you send an object between JavaScript and ActionScript it is serialized/deserialized and converted from a JavaScript object to an ActionScript object, or vice versa, but the saySomething function/method is not converted to a ActionScript function. Executable code is not converted. Basic types like strings, numbers, booleans, arrays and objects are converted, but not functions.

Also, ctx won't be a reference to the object you created in JavaScript, it will be a copy of the object (serialized and deserialized).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.