首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态发布swfobject外部接口回调方法未定义

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

Stack Overflow用户
提问于 2013-11-06 18:34:51
回答 1查看 677关注 0票数 0

某位天才能帮助解决这个问题吗!我们会非常感激的

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

Flash操作脚本示例

代码语言:javascript
复制
**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对象动态嵌入闪存,因此当从html的列表中处理一个单击事件时,应该将相应的config.xml加载到闪存播放器上。

示例HTML代码:

代码语言:javascript
复制
$( 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);
});

回调函数

代码语言:javascript
复制
//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"

代码语言:javascript
复制
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计时器,

错误是,

未明的TypeError:对象#没有方法'sendTextFromHtml‘

EN

回答 1

Stack Overflow用户

发布于 2013-11-07 16:31:45

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

代码语言:javascript
复制
function swfLoadEvent(swf, fn){
    swf.sendTextFromHtml("config.xml");
    ...
}

然后被调用为

代码语言:javascript
复制
swfLoadEvent(e.ref, function(){
    ...
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19820009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档