动态发布swfobject外部接口回调方法未定义

时间:2013-11-06 18:34:51

标签: actionscript callback swfobject externalinterface

有些天才可以帮助解决这个问题!非常感谢

实际上我通过名为config.xml的配置文件加载了flash音乐播放器

Flash播放器动作脚本示例

**myUltimateMp3Player.loadConfig("config.xml");**

import flash.external.ExternalInterface; 
stop();
// ExternalInterface receive
if (ExternalInterface.available) { 
   ExternalInterface.addCallback("sendTextFromHtml", null, function(val:String):Void {    
   myUltimateMp3Player.loadConfig(val); }); 
}

我试图使用Swf对象动态嵌入flash,因此当从html列表中处理click事件时,相应的config.xml应该加载到flash播放器上。

示例HTML代码:

$( document ).on( "click", "#Musiclist li", function() {    
    var c = "youtube-playlist";
    $("#media-" + c).remove();
    createMedia(c);
    var id=this.id;
    var idxml=id+".xml";
    var swfPanel="media-" + c;
    var flashvars = {};
    var params = {};
    params.swliveconnect = "true";
    params.allowfullscreen = "true";
    params.allowscriptaccess = "always";
    var attributes = {};
    attributes.id = "flashobj";
    attributes.name = "flashobj";
    swfobject.embedSWF("source.swf", "flashcontent", "100%", "100%", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes,callbackFn);
});

回调功能

//This function is invoked by SWFObject once the <object> has been created
var callbackFn = function (e){
    //Only execute if SWFObject embed was successful
    if(!e.success || !e.ref){ return false; }
    swfLoadEvent(function(){
       var obj=e.ref;
       obj.sendTextFromHtml("config.xml");
       alert("The SWF has finished loading!");
    });
};

为SWF的PercentLoaded值保留计时器的功能,等待它达到“100”

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

所以我无法弄清楚我做错了什么,

错误获取是,

  

未捕获的ReferenceError:未定义e

如果我没有使用swfLoadEvent Timer,

错误获取是,

  

未捕获TypeError:对象#没有方法'sendTextFromHtml'

1 个答案:

答案 0 :(得分:0)

e不是全局变量。尝试修改swfLoadEvent函数以将对swf的引用作为参数传递:

function swfLoadEvent(swf, fn){
    swf.sendTextFromHtml("config.xml");
    ...
}

然后被调用为

swfLoadEvent(e.ref, function(){
    ...
});