flashswfupload

It is possible to Communicate Between Flash and JavaScript without embedding


I have found this cool file-upload repo by mailru, it called FileAPI. The FileAPI uses .swf file as debugging tool. How this works without embedding the .swf file??


Solution

  • How this works without embedding the .swf file??

    They seem to be dynamically updating the html page (to now have the SWF embeded). This means using innerHTML to generate new content which was not originally coded in the html file. You can check a basic guide about innerHTML here.

    Looking at FileAPI.js, onwards from line 3590 we see they indeed use innerHTML to embed a Flash object. It becomes embeded (dynamically) when the right Javascript function is triggered.

    Some short snippet of their code is below :

    /**
     * Publish flash-object
     *
     * @param {HTMLElement} el
     * @param {String} id
     * @param {Object} [opts]
     */
    publish: function (el, id, opts){
        opts = opts || {};
        el.innerHTML = _makeFlashHTML({
              id: id
            , src: _getUrl(api.flashUrl, 'r=' + api.version)
            //, src: _getUrl('http://v.demidov.boom.corp.mail.ru/uploaderfileapi/FlashFileAPI.swf?1')
            , wmode: opts.camera ? '' : 'transparent'
            , flashvars: 'callback=' + (opts.onEvent || 'FileAPI.Flash.onEvent')
                + '&flashId='+ id
                + '&storeKey='+ navigator.userAgent.match(/\d/ig).join('') +'_'+ api.version
                + (flash.isReady || (api.pingUrl ? '&ping='+api.pingUrl : ''))
                + '&timeout='+api.flashAbortTimeout
                + (opts.camera ? '&useCamera=' + _getUrl(api.flashWebcamUrl) : '')
                + '&debug='+(api.debug?"1":"")
        }, opts);
    },
    
    ... etc etc etc ...