开发者

Javascript loses communication with flash when moved inside dom

Code inside 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_开发者_JS百科id);
    }
}

Html:

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

    </div>
</div>

Javascript: when dom is loaded:

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

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

That's it. When i'm trying to upload somethin, startupload function inside flash is not working anymore.

Calling Actionscript this way:

/* 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 is calling javascript functions from inside just fine, but javascript is not.

What is the problem? How to rebind startupload function?


You have the same problem with this.

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

When you move flash it's CSS box is destroyed and recreated. For various reasons (refer to the link for more) the plugin state is stored in the CSS box and not in the DOM object and therefore the plugin is "reset". That means that the object variable you use to communicate with the plugin no longer hold a valid reference since the plugin has been reloaded.


you accessing document body, but your swf is deeper, so access it directly:

so not document.getElementById(movieName) but document.getElementById(e_upload).getElementById(movieName)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜