外部接口和swfobject.js问题 [英] external interface and swfobject.js issue

查看:133
本文介绍了外部接口和swfobject.js问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前,在工作中我开发了一个视频播放器使用闪光灯,外接接口和swfobject.js项目。我使用的外部接口,方便的JavaScript和ActionScript之间的通信。这个伟大的工程。目前,我的工作就延伸到这个原因,我需要从我已经写好的推断逻辑。我正在使用这两个应用程序相同的SWF文件,但在扩展我不能让Flash对象识别我的电话。由于我使用的是同一个SWF对象,我知道,我的问题是,在JavaScript中,我只是不知道在哪里。我使用jQuery库。如果没有进一步再见,这里是我code。

Several months ago for a project at work i developed a video player using flash, external interface and swfobject.js. I used external interface to facilitate communication between javascript and actionscript. This works great. Currently I am working on an extension to this that requires me to extrapolate logic from what i already written. I am using the same swf file in both applications, but in the extension i can't get the flash object to recognize my calls. Since i am using the same swf object i know that my problem is in the javascript, i just don't know where. I am using the JQuery Library. Without further adieu here's my code.

在我的js文件的底部,我有以下几点:

At the bottom of my js file i have the following:

$(function(){
     //the video player shouldn't be built until the user presses the div with 'video-btn' class
    $('.video-btn').click(function(){
         var videoplayer = new VideoPlayer();
         videoplayer.addVideoPlayer();
         //external interface function
         videoplayer.player.loadVideo();
    });
});

下面是 VideoPlayer.addVideoPlayer()的定义,它的相关辅助功能:

Here's the definition for VideoPlayer.addVideoPlayer() and it's relevant helper functions:

//inside of VideoPlayer object definition
this.addVideoPlayer = function(){
     var that = this;
     $('body').append('<div id="no-flash"></div>');

     //uses swfobject.js to replace the div i just appended with the flash object
     //This works fine.  the flash object replaces the div as intended
     that.embedFlashObject();
     //that.player is (supposed to be) a reference to flash object
     that.player = that.getFlashObject();
};

this.embedFlashObject = function(){
     var that = this;

     //set up all the variables to pass to swfobject.embedSWF

     //this method removes my div and replaces it with an object element that contains the swf file
     //the object tag gets an id which is specified.  Let's assume it's 'vp'
     swfobject.embedSWF(swfFile, 'no-flash', width, hieght, '9.0.0', ... );
};

this.getFlashObject = function(){
     var that = this;

     //this method returns the flash object to make external interface calls on
     //this the method prescribed by swfobject api  
     var videoObj = swfobject.getObjectById('vp');
     if(typeOf videoObj == 'undefined')
     {
          //check if useragent string is IE
          var isIE = navigator.userAgent.match(/MSIE/i);
          videoObj = isIE ? window['vp'] : document['vp'];
     }
     return videoObj;
};

在我的 $(函数(){...}); 块,当指令 videoplayer.player.loadMedia(); 我得到读

In my $(function(){..}); block, when the command 'videoplayer.player.loadMedia();' I get an error that reads

.loadMedia不是函数。

.loadMedia is not a function.

在此项目中的previous版本(在此我使用完全相同的SWF文件)我没有得到这个错误。

In the previous version of this project (in which i use the exact same swf file) i do not get this error.

我不认为我失去了任何严重的逻辑错误,而且我知道它很难肯定地说'这是你的问题,......当在略寻找擦洗code。在代替一个明确的答复,我会采取建议如何调试这个问题。我一直在玩aorund在浏览器控制台,我发现我的VideoPlayer对象的'玩家'属性为空。当我跑在同一个控制台的查询对这个项目的工作版本,它吐回对象标记。我不能直接设置对象的标签,因为这将在previous版本所使用的约定,我需要保持打破。

I don't think i am missing any severe logical errors, and i know its difficult to say definitively 'this is your issue,....' when looking at abbreviated and scrubbed code. In lieu of a definite answer i'll take suggestions as to how to debug this issue. I've been playing aorund in the browser console and i've found that the 'player' attribute of my VideoPlayer object is null. When i ran the same console query against the working version of this project it spits back the object tag. I can't directly set the object tag, because it will break with the conventions used in the previous version which i need to maintain.

帮助!!!!!!!!!!!!!!!

HELP!!!!!!!!!!!!!!!

推荐答案

所以我想通了,我的问题了。尽管是稳健的问题描述我尽了最大努力,我离开了这将可能有助于解决我的问题的一个关键的事实。我被转移到一个实际的开发服务器之前,在本地开发我的申请。当使用在本地范围内Flash应用程序,从互联网通信默认情况下禁用。如果谷歌Adobe安全设置,上面的链接之一,将带你到一个Adobe安全设置页面,您可以cchose要允许这个外部通信在本地计算机上的文件夹。我的SWF文件将试图早早就为我们的服务器的连接befor初始化外围回调,如果不能做到这一点,它只是等待,因而没有我的功能正变得声明的函数。其实,我通过这个项目我的初始迭代工作时有这个问题,但没想到的是,直到昨天。

So i figured out what my problem was. Despite my best efforts to be robust in description of the problem, i left out one key fact that would probably have helped to solve my issue. I was developing my application locally before moving to an actual development server. When using a flash application in a local context, communications from the internet are disabled by default. If you google 'adobe security settings', one of the top links will take you to an adobe security settings page where you can cchose folders on your local machine that you want to allow this external communication. My swf file would tries early on to make a connection to our servers befor initializing the external call backs, if it can't do that it just waits, and thus none of my functions were becoming declared functions. I actually had this problem when working through my initial iteration of this project, but didn't think of it until yesterday.

感谢您为大家谁提供的解决方案。做完这两次我可以保证的是,一切都已经表明这里是一些可能容纳一个人了,而试图编程和外部接口的Flash应用程序。

Thank you for everyone who supplied solutions. Having done this twice i can vouch for the fact that everything that has been suggested here is something that might hold a person up while trying to program and external interface flash application.

这篇关于外部接口和swfobject.js问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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