Javascript to flash communication

后端 未结 6 944
清歌不尽
清歌不尽 2021-02-06 05:59

I am trying to call a Actionscript function from javascript but I am having problems in Internet Explorer. I am using Swiff.remote in mootools 1.2.1 to call the actionscript fun

6条回答
  •  借酒劲吻你
    2021-02-06 06:42

    I'm not familiar with the Swiff plugin, but you don't need a plugin to call flash functions from Javascript. It's even easier to do it natively.

    From AS:

    //1. calling javascript function from Flash.
    ExternalInterface.call("sendData",tempStr);
    // argument 1: javascript function, argument 2: data/variables to pass out.
    //2. calling javascript function from Flash with recursion.
    var returnValue:String = ExternalInterface.call("sendReturn",tempStr).toString();
    //3. setting up a callback function for javascript
    ExternalInterface.addCallback("callFlash",flashResponse);
    // argument 1: function name called by javascript, argument 2: function on the Flash side.
    // AS2 version looks like this : ExternalInterface.addCallback("callFlash",null,flashResponse);
    

    From JS:

    //1. javascript function as called from Flash.
    function sendData(val){
        alert(val);
        document.flashForm.flashOutput.value = val;
    }
    
    //2. javascript function with recursion.
    function sendReturn(val){
        var tempData = "Hello from JS";
        return tempData + ' :return';
    }
    
    //3. calling Flash function with javascript.
    function sendToFlash(val){
        window['flash'].callFlash(val);
    }
    

提交回复
热议问题