Detect if Flash application loaded correctly using Javascript?

后端 未结 4 1637
栀梦
栀梦 2020-12-16 03:48

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

4条回答
  •  半阙折子戏
    2020-12-16 04:39

    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('
    '); 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); }

提交回复
热议问题