1

I understand that ExternalInterface.call('functionName', arguments); in ActionScript 3 can be used to communicate with Javascript function functionName(arguments) defined on the HTML page.

But what about a custom object instance? Say that I have:

(function (factory, $, undefined) {

    factory.worker = function () {
        ...
    };

    factory.worker.prototype.init = function (params) {
        ...
    };

    factory.worker.prototype.flash_tell_me_something = function (params) {
        ...
    };

}(window.factory = window.factory || {}, jQuery));

And in order to use it, I combine it with jQuery to create an instance, plus the Flash object:

$(document).ready(function () {
    var myworker = new factory.worker();
    myworker.init();
    var myloadedcallback = function () {
    };
    flashVars = {loadedCallback: myloadedcallback};
    ...
    swfobject.embedSWF(swfUrl, id, 215, 138, version, null, flashVars, params);
});

How do I call myworker.flash_tell_me_something(...) from Flash?

1 Answer 1

1

Try this solution:

    if(ExternalInterface.available)
    {
        ExternalInterface.call("window.myworker.flash_tell_me_something", "hello");
    }

You can also call worker directly, rather than window.worker if they are (worker and flash object) in the same namespace.

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

3 Comments

Hi, thanks for the answer. My real situation here contain nested level of 'myworker', the call comes from lower level. It might be something like this: window.myworker1.myworker2.myworker3.call. The problem is myworker3 do not know the nesting graph. Could you elaborate your answer in the situation where level of myworker and its name is unknown?
so you want to say, that flash don't know the path to the target worker? If so, you can add this path to the flash vars or add some 'setupFlashJSBridge' callback to the flash and pass this parameter in the runtime.
Maybe you need something like this: in your flash file you can access passed flashvars via loaderInfo.parameters so maybe this can work for you ExternalInterface.call( MovieClip(this.root).loaderInfo.parameters.loadedCallback, 'hello');

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.