BlazeDS Flex-AJAX 桥接负载不适用于 Ext.JS

发布于 2024-08-19 14:51:58 字数 2732 浏览 5 评论 0原文

Flex-AJAX 桥的 FDMSLib 有一个加载函数,可以将 flash 对象呈现到调用它的页面上。当使用 Ext.JS 时,这会导致问题,因为插入的对象可能会被另一个渲染函数丢弃,或者在页面渲染期间导致冲突,因此我尝试重写加载函数,以便其 Ext.JS (可能还有其他) JS框架)友好。

这是原来的函数。

FDMSLibrary.load = function(path, callback)
{
    var result = "<object id='_fesLib' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' \
                 codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,5,0,0' \
                  height='1' width='1'> \
                 <param name='flashvars' value='bridgeName=flash'/> \
                 <param name='AllowScriptAccess' value='always'/> \
                 <param name='src' value='"+ (path != undefined ? path : "") + "'/> \
                 <param name='wmode' value='transparent' /> \
                 <embed name='_fesLib' pluginspage='http://www.macromedia.com/go/getflashplayer' allowScriptAccess='always'\
                 src='" + (path != undefined ? path : "") + "' height='1' width='1' flashvars='bridgeName=flash'/> \
              </object>";
    document.write(result);

   // todo:need a callback and variable here so you can keep track that both the fabridge and the fdmsbridge are available
    FDMSLibrary.addInitializationCallback("flash", callback);

  // register for call back when the FABridge has completed initialization
    FABridge.addInitializationCallback("flash", FABridge_ready);
 }

我已将其替换为以下内容:

loadFDMSBridge: function(path,callback) {
    var FABridgeSWF = new Ext.FlashComponent({
        id : '_fesLib',
        height: '1',
        width: '1',
        flashVars : {
            bridgeName:'flash'
        },
        wmode : 'transparent',
        flashVersion : '8.5.0.0',
        renderTo : Ext.getBody(),
        url : path,
        listeners : {
            'render' : {
                fn : this.initBridge,
                scope : this
            }

        }
    });


},
initBridge : function () {
        FDMSLibrary.addInitializationCallback("flash", this.initPolling);
        FABridge.addInitializationCallback("flash", FABridge_ready);
}

flash 对象渲染到页面,它使用对象中的数据属性而不是 src 参数,但我认为这对于渲染 flash 对象是正确的。

我遇到的问题是,当我调用 FDMSLibrary.addInitializationCallback 函数时,桥接器似乎尚未准备好。

swf 文件告诉 JavaScript 已经可以使用了。我非常确定 swf 没有问题,因为我使用相同的 swf 和 javascript 库启动并运行了一个简单的测试页面,但没有任何其他 javascript、内容等的干扰。感觉好像 swf 没有被加载和“执行”,Firebug 似乎支持这一点,但我真的不知道为什么或我错过了什么。

如果您想查看 FABridge 的完整 JavaScript 库和 ActionScript 源代码,您可以在 Adob​​e 的 subversion 存储库中找到它们:fds ajax 桥存储库路径

预先感谢您的帮助

The FDMSLib for the Flex-AJAX bridge has a load function that renders a flash object to the page where ever it is called. This causes problems when using Ext.JS as the inserted object can either be discarded by another render function or cause conflicts during the rendering of the page, so I'm trying to rewrite the load function so that its Ext.JS (and probably other JS framework) friendly.

This is the original function.

FDMSLibrary.load = function(path, callback)
{
    var result = "<object id='_fesLib' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' \
                 codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,5,0,0' \
                  height='1' width='1'> \
                 <param name='flashvars' value='bridgeName=flash'/> \
                 <param name='AllowScriptAccess' value='always'/> \
                 <param name='src' value='"+ (path != undefined ? path : "") + "'/> \
                 <param name='wmode' value='transparent' /> \
                 <embed name='_fesLib' pluginspage='http://www.macromedia.com/go/getflashplayer' allowScriptAccess='always'\
                 src='" + (path != undefined ? path : "") + "' height='1' width='1' flashvars='bridgeName=flash'/> \
              </object>";
    document.write(result);

   // todo:need a callback and variable here so you can keep track that both the fabridge and the fdmsbridge are available
    FDMSLibrary.addInitializationCallback("flash", callback);

  // register for call back when the FABridge has completed initialization
    FABridge.addInitializationCallback("flash", FABridge_ready);
 }

I've replaced this with the following :

loadFDMSBridge: function(path,callback) {
    var FABridgeSWF = new Ext.FlashComponent({
        id : '_fesLib',
        height: '1',
        width: '1',
        flashVars : {
            bridgeName:'flash'
        },
        wmode : 'transparent',
        flashVersion : '8.5.0.0',
        renderTo : Ext.getBody(),
        url : path,
        listeners : {
            'render' : {
                fn : this.initBridge,
                scope : this
            }

        }
    });


},
initBridge : function () {
        FDMSLibrary.addInitializationCallback("flash", this.initPolling);
        FABridge.addInitializationCallback("flash", FABridge_ready);
}

The flash object is rendered to the page, it uses the data attribute in object rather than a src param, but I assume this is correct for rendering flash objects.

The problem I'm having with this is that when I call the FDMSLibrary.addInitializationCallback function it would appear that the bridge is not ready.

The javascript is told by the swf file that it is ready to be used. I'm pretty certain that its no a problem with the swf as I have an simple test page up and running using the same swf and javascript libraries, but without any interference from any other javascript, content and so on. It kind of feels like the swf isn't being loaded and "executed" and Firebug would seem to back this up, but I don't really know why or what I've missed.

If you would like to see the full javascript libraries and the actionscript source for the FABridge you can find them here in Adobe's subversion repo : fds ajax bridge repo path

Thanks in advance for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

为你拒绝所有暧昧 2024-08-26 14:51:58

不确定,但您可以尝试使用 afterrender 事件而不是 render。因为它发生在渲染周期的后期(好吧,在它之后:)它可能会有所帮助 - 我知道过去在组件的某些部分实际上完成渲染之前渲染触发存在问题(这就是后来添加 afterrender 事件的原因)。

如果这不起作用,另一件事可能是尝试稍微推迟您的 initBridge 功能。这有点牵强,但我之前见过这样的情况,要么是 JS 执行存在时序问题,要么可能是某些阻塞导致了这种症状。推迟代码将延迟其执行并在新线程上执行它,这可能会解决问题。这不是最好的解决方案,但我已经通过这种方式解决了几个浏览器的怪癖。例如:

initBridge : function () {
    (function(){
        FDMSLibrary.addInitializationCallback("flash", this.initPolling);
        FABridge.addInitializationCallback("flash", FABridge_ready);
    }).defer(500, this);
}

至少这可以确认是否是计时/阻塞问题。您可以向上或向下调整 500(毫秒),看看行为是否有任何差异。

Not sure, but you might try the afterrender event instead of render. As it happens later in the rendering cycle (well, after it :) it might help -- I know that there have been issues in the past with render firing before certain pieces of a component were actually done rendering (which is why the afterrender event was later added).

Another thing if that doesn't work might be to try deferring your initBridge functionality slightly. This is a bit of a stretch, but I've seen the case before where there is either a timing issue with the JS execution, or possibly some blocking that causes this type of symptom. Deferring your code will both delay its execution and execute it on a new thread, which may solve the problem. Not the best solution, but I've worked around several browser quirks this way. E.g.:

initBridge : function () {
    (function(){
        FDMSLibrary.addInitializationCallback("flash", this.initPolling);
        FABridge.addInitializationCallback("flash", FABridge_ready);
    }).defer(500, this);
}

At least this might confirm whether or not it's a timing/blocking issue. You can adjust the 500 (ms) up or down to see if you hit any difference in behavior.

就此别过 2024-08-26 14:51:58

@bmoeskau:感谢您的有用建议。

根据您的建议再次查看我的代码,我意识到了一些事情。

首先是我对错误的文件进行了更改。我制作了一个独立版本,并且不小心编辑了这些文件,而不是 ext.js 应用程序。

其次,通过所有的更改、测试和一般混乱,我已经成功地超载了我的一些函数,这意味着调用了错误的函数。无论我对我正在查看的函数做了多少更改,它都不会被调用。

上面的代码实际上按照说明工作。

@bmoeskau : thanks for the helpful suggestions.

Looking at my code again with your suggestions I realised a couple of things.

First was that I was making changes in the wrong files. I'd made a standalone version and had accidentally been editing those files and not the ext.js application.

Secondly, with all the changes,testing and general messing about I had managed to overload some of my functions, which meant that the wrong functions were being called. No matter how much I changed the function I was looking at it never got called.

The above code actually works as stated.

满身野味 2024-08-26 14:51:58

只是为了整理一下:

我遇到了由 Firefox bug 和 swfobjects(Ext.Flash 组件的底层库)。我最终不得不将原始 html 从 FDMSLib load() 函数推送到 DOM,而不是使用 Ext 对象。

    // spec up the flash object for FABridge
    var foSpec = {
            tag : 'object',
            id : '_fesLib',
            classid : 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
            codebase: 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,5,0,0',
            height :'1',
            width : '1',
            cn : [
                    {tag:'param', name:'flashvars', value:'bridgeName=flash'},
                    {tag:'param', name:'AllowScriptAccess', value:'always'},
                    {tag:'param', name:'src', value:path},
                    {tag:'param', name:'wmode', value:'transparent'},
                    {tag:'embed', name:"_fesLib", pluginspage:'http://www.macromedia.com/go/getflashplayer', allowScriptAccess:'always', src:path, height:'1', width:'1', flashvars:'bridgeName=flash'}                   
            ]

    };
    // Add it to the end of the body
    Ext.getBody().createChild(foSpec);

我隐约记得某处的一篇文章说 FABridge 使用“嵌入”标签,并且由于 swfobject 不插入“嵌入”标签,这也可能导致问题。

除此之外,Ext.FlashComponent 的 flashParams 属性引用了此 adobe 技术说明 所需参数。这表明仅包含 Flash 对象的对象必须包含参数“movie”。 swfobject 强制删除任何名为“movie”的参数。

有了这个,在任何地方都没有太多乐趣!

Just to tidy this up :

I had continuing issues courtesy of a Firefox bug and swfobjects (the underlying library for Ext.Flashcomponent). I ended up having to push the original html from the FDMSLib load() function into the DOM rather than use the Ext object.

    // spec up the flash object for FABridge
    var foSpec = {
            tag : 'object',
            id : '_fesLib',
            classid : 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
            codebase: 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,5,0,0',
            height :'1',
            width : '1',
            cn : [
                    {tag:'param', name:'flashvars', value:'bridgeName=flash'},
                    {tag:'param', name:'AllowScriptAccess', value:'always'},
                    {tag:'param', name:'src', value:path},
                    {tag:'param', name:'wmode', value:'transparent'},
                    {tag:'embed', name:"_fesLib", pluginspage:'http://www.macromedia.com/go/getflashplayer', allowScriptAccess:'always', src:path, height:'1', width:'1', flashvars:'bridgeName=flash'}                   
            ]

    };
    // Add it to the end of the body
    Ext.getBody().createChild(foSpec);

I vaguely recall a post somewhere that says that FABridge uses the "embed" tag and as swfobject doesn't insert an "embed" tag this may also have been causing issues.

To add to this, the flashParams property of Ext.Flashcomponent makes reference to this adobe technote on required params. This states that an object only inclusion of a flash object must include the param "movie". swfobject forcibly removes any param with the name "movie".

Not much fun to be had anywhere with this!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文