0

在我们的网站中,我在html中嵌入了一个flash builder制作的flash,flash大小超过2M。由于网络不好,加载flash可能需要30秒。我怎么知道浏览器已经完全加载了 Flash?

4

2 回答 2

1

您可以轮询 SWF 以获取其PercentLoaded值。

这是一种方法(从learnswfobject.com复制的代码):

function swfLoadEvent(fn){
    //Ensure fn is a valid function
    if(typeof fn !== "function"){ return false; }
    //This timeout ensures we don't try to access PercentLoaded too soon
    var initialTimeout = setTimeout(function (){
        //Ensure Flash Player's PercentLoaded method is available and returns a value
        if(typeof e.ref.PercentLoaded !== "undefined" && e.ref.PercentLoaded()){
            //Set up a timer to periodically check value of PercentLoaded
            var loadCheckInterval = setInterval(function (){
                //Once value == 100 (fully loaded) we can do whatever we want
                if(e.ref.PercentLoaded() === 100){
                    //Execute function
                    fn();
                    //Clear timer
                    clearInterval(loadCheckInterval);
                }
            }, 1500);
        }
    }, 200);
}

//This function is invoked by SWFObject once the <object> has been created
var callback = function (e){

    //Only execute if SWFObject embed was successful
    if(!e.success || !e.ref){ return false; }

    swfLoadEvent(function(){

        //Put your code here
        alert("The SWF has finished loading!");

    });

};

swfobject.embedSWF("movie.swf", "flashcontent", "550", "400", "9", false, false, false, false, callback);
于 2012-11-21T19:09:13.737 回答
0

pipwerks 的答案工作正常。你甚至可以获得更低的价值:而不是 1500 只有 100 就可以了。

但我在 Firefox 上遇到了一些问题。而不是超时,initialTimeout 应该是一个 timeInterval,因为有时在 FF 上,第一次调用你会有未定义的 e.ref.PercentLoaded,但下一次调用会很好。当然你需要调用 clearInterval(initialTimeout); 如果是真的。

所以你会得到类似的东西:

    var initialTimeout = setInterval(function (){
     if(typeof e.ref.PercentLoaded !== "undefined" && e.ref.PercentLoaded()){
         clearInterval(initialTimeout);
于 2016-05-26T18:41:45.713 回答