He Shiming
He Shiming

Reputation: 5819

Object oriented Javascript, communication with Flash

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?

Upvotes: 1

Views: 83

Answers (1)

fsbmain
fsbmain

Reputation: 5267

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.

Upvotes: 1

Related Questions