【问题标题】:Javascript loses communication with flash when moved inside domJavascript 在 dom 内移动时失去与 flash 的通信
【发布时间】:2010-09-02 16:46:11
【问题描述】:

Actionscript 内的代码:

var methodName4:String = "startupload";
var instance4:Object = null;
var method4:Function = startupload;
var wasSuccessful4:Boolean = ExternalInterface.addCallback(methodName4, instance4, method4);
function startupload(currently_uploading_id) {

    /* If there is still more photos to upload, then proceed to next one */
    if((max_photo_number - session_photos))
    {
        uploadthis(selected_photos,currently_uploading_id);
    }
}

HTML:

<div id="e_upload" class="hidden">
    <div id="upload_container">

    </div>
</div>

Javascript: 加载 dom 时:

var cached_flash = $('#e_upload').html();
$('#e_upload').html('');

When generating html via javascript:
$(cached_flash).appendTo(full_ad.find('#e_upload_wrapper')).show();

就是这样。当我尝试上传某些东西时,flash 内的启动加载功能不再起作用。

以这种方式调用 Actionscript:

/* Sending back to Flash */
function thisMovie(movieName) {

    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }

}

thisMovie('fileref').startupload(currently_uploading_array_slot);

Actionscript 可以从内部调用 javascript 函数,但 javascript 不是。

有什么问题?如何重新绑定startupload函数?

【问题讨论】:

  • 当我定位绝对并移动需要的地方时,一切正常。但是当我复制 html 并放入新位置时,绑定函数不再起作用。如何在新的地方重新绑定它们?

标签: javascript flash


【解决方案1】:

你也有同样的问题。

Can I move a Flash object within the DOM without it reloading?

当您移动 Flash 时,它的 CSS 框会被破坏并重新创建。由于各种原因(有关更多信息,请参阅链接),插件状态存储在 CSS 框中而不是 DOM 对象中,因此插件被“重置”。这意味着您用于与插件通信的对象变量不再持有有效的引用,因为插件已被重新加载。

【讨论】:

    【解决方案2】:

    您访问的是文档正文,但您的 swf 更深,所以直接访问它:

    所以不是document.getElementById(movieName),而是document.getElementById(e_upload).getElementById(movieName)

    【讨论】:

    • 有意思,我试试。但我认为问题不在于这个。如果有帮助,我会在这里检查并发布。
    • 这是 plugin_container.exe 或 Firefox 内部的某种错误,甚至可能是因为我使用的是旧闪存并编译成 8.0。不管它是什么,我已经将 flash 绝对定位在页面上,而没有将其移动到 dom 中。这解决了我的问题。
    猜你喜欢
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    相关资源
    最近更新 更多