检测Flash应用程序是否使用Javascript正确加载? [英] Detect if Flash application loaded correctly using Javascript?

查看:155
本文介绍了检测Flash应用程序是否使用Javascript正确加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的产品打开一个网页浏览器,并将其指向包含本地Flash应用程序的HTML文件。如何以编程方式检测此文件是否成功加载,以及是否抛出异常?有没有办法做到这一点使用Javascript?



从外部检查文件是否存在磁盘是不够的,因为我看到其他故障发生(竞争条件可能涉及)。

解决方案

回答我自己的问题: https://sourceforge.net/forum/message.php?msg_id=5929756


  1. 定义一个在加载Flash时应该调用的Javascript函数。
  2. 从您的Flash文件的顶部调用此方法。

  3. 使用一个计时器来检测回调是否永远不会被调用。
  4. 喜欢从Flash调用Javascript函数,而不是从Javascript调用Flash函数。无论哪种方式,你不能调用尚未加载的函数。保证浏览器在从Flash中调用Javascript函数之前已经完成了加载Javascript函数的工作,而不是保证Flash在从Javascript调用它之前完成加载Flash函数。

下面是一个例子:


  • 我正在使用 swfobject 嵌入Flash。
  • 我使用FlashVars告诉Flash要调用哪个Javascript函数。如果页面上有多个Flash对象,这非常有用。



Flash
$ b

  var params:Object = LoaderInfo(this.root.loaderInfo).parameters; 
if(ExternalInterface.available)
{
var onLoaded:String = params [onLoaded];
if(onLoaded!= null)
ExternalInterface.call(onLoaded,true);

Javascript

  var flashLoaded = false; 
var flashTimer;

函数onFlashLoaded()
{
flashLoaded = true;
clearTimeout(flashTimer);

$ b $函数onFlashTimeout()
{
if(!isFlashLoaded)
{
//移除Flash对象部分加载
$(#videoFeed)。
$(#videoFeed)。append('< div id =flashObject>< / div>);
alert(无法加载视频播放器);
}
clearTimeout(flashTimer);


函数connectToVideo()
{
var flashvars = {};
flashvars.onLoaded =onFlashLoaded;

var params = {};
params.menu = false;

var attributes = {};

isFlashLoaded = false;
flashTimer = setTimeout(onFlashTimeout(),5000);

swfobject.embedSWF(flash / VideoFeed.swf,flashObject,800,600,11,expressInstall.swf,flashvars,params,attributes);
}


My product opens a web browser and points it at an HTML file containing a local Flash application. How do I detect programmatically whether this file loaded successfully and if not what exception was thrown? Is there a way to do this using Javascript?

Checking externally whether the file exists on disk is not enough because I've seen other failures occur (race conditions might be involved).

解决方案

Answering my own question: https://sourceforge.net/forum/message.php?msg_id=5929756

  1. Define a Javascript function that should be invoked if Flash loaded.
  2. Invoke this method from the top of your Flash file.
  3. Use a timer to detect if the callback is never invoked.
  4. Prefer invoking Javascript functions from Flash rather than invoking Flash functions from Javascript. Either way you cannot invoke a function that has not been loaded yet. It is far easier to guarantee that the browser has finished loading your Javascript function before invoking it from Flash, than guaranteeing that Flash finished loading your Flash function before invoking it from Javascript.

Here is an example:

  • I am using swfobject to embed Flash.
  • I use FlashVars to tell Flash which Javascript function to invoke. This is useful if there are multiple Flash objects on the page.

Flash

var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
if (ExternalInterface.available)
{
    var onLoaded:String = params["onLoaded"];
    if (onLoaded != null)
        ExternalInterface.call(onLoaded, true);
}

Javascript

var flashLoaded = false;
var flashTimer;

function onFlashLoaded()
{
    flashLoaded = true;
    clearTimeout(flashTimer);
}

function onFlashTimeout()
{
    if (!isFlashLoaded)
    {
        // Remove the Flash object in case it is partially loaded
        $("#videoFeed").empty();
        $("#videoFeed").append('<div id="flashObject"></div>');
        alert("Failed to load video player");
    }
    clearTimeout(flashTimer);
}

function connectToVideo()
{
    var flashvars = {};
    flashvars.onLoaded = "onFlashLoaded";

    var params = {};
    params.menu = false;

    var attributes = {};

    isFlashLoaded = false;
    flashTimer = setTimeout("onFlashTimeout()", 5000);

    swfobject.embedSWF("flash/VideoFeed.swf", "flashObject", "800", "600", "11", "expressInstall.swf", flashvars, params, attributes);
}

这篇关于检测Flash应用程序是否使用Javascript正确加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆