动态插入flash对象的javascript和flash通信问题

发布于 2024-10-16 03:09:45 字数 1551 浏览 2 评论 0原文

我正在使用ExternalInterface 与AS2 进行javascript 和flash 通信。这非常适合嵌入在虚拟页面中的 Flash 游戏,并且来自和到 flash/javascript 的调用工作正常,没有任何错误。

在我的新页面中,我在 div 中动态插入 flash 对象(通过 jquery)。问题是,当我调用 flash_Obj.JS2Flash_SetValue(val); 这样的 flash 函数时,它表示 JS2Flash_SetValue 不是已定义的函数。尽管当我检查对象/嵌入元素是否存在时,它确实显示了该元素(我使用 firebug 进行调试)。

否则,当我在虚拟页面中测试 javascript 和 flash 通信时,它运行时没有任何错误。

我研究过这个问题 - Javascript 在 dom 内移动时会失去与 flash 的通信

但是这没什么帮助。

有人可以建议一个解决方案吗?

flash代码

ExternalInterface.addCallback("JS2Flash_SetValue", null, SetValue);
var fVal:String;
function SetValue(_val:String):Void
{       
    ExternalInterface.call("ShowAlert", _val + " has received from JS.");
}

JS代码

function SetValue1(val) // first approach i tried
 {          
  var flash_Obj = $('#flashGame').[0];
  flash_Obj.JS2Flash_SetValue(val);

  var flash_Obj1 = $('#flashGame').get(0);
  flash_Obj1.JS2Flash_SetValue(val);
 }

 function SetValue2(val) // another approach i tried
 {           
   var flash_Obj = getMovieName('flashGame');    
   flash_Obj.JS2Flash_SetValue(val);
 }

 function getMovieName(movieName) {
   if (navigator.appName.indexOf("Microsoft") != -1) {
       return window[movieName];
   }
   else {
       return document[movieName];
   }
 }

 function ShowAlert(msg) {
   alert(msg);
 }

谢谢

I was working with javascript and flash communication with AS2 using ExternalInterface. This works well with my flash game being embedded in a dummy page and calls from and to flash/javascript were working fine without any errors.

In my new page, I am dynamically inserting the flash object in a div (by jquery). The problem is that when I call the flash function like flash_Obj.JS2Flash_SetValue(val); it says that JS2Flash_SetValue is not a defined function. Although when I check for the presence of the object/embed element, it does show the element (i used firebug to debug).

Otherwise, when in a dummy page, I was testing javascript and flash communication, it ran without any errors.

I have looked in to this question -
Javascript loses communication with flash when moved inside dom

but it wasn't much of help.

Can someone please suggest a solution?

flash code

ExternalInterface.addCallback("JS2Flash_SetValue", null, SetValue);
var fVal:String;
function SetValue(_val:String):Void
{       
    ExternalInterface.call("ShowAlert", _val + " has received from JS.");
}

JS code

function SetValue1(val) // first approach i tried
 {          
  var flash_Obj = $('#flashGame').[0];
  flash_Obj.JS2Flash_SetValue(val);

  var flash_Obj1 = $('#flashGame').get(0);
  flash_Obj1.JS2Flash_SetValue(val);
 }

 function SetValue2(val) // another approach i tried
 {           
   var flash_Obj = getMovieName('flashGame');    
   flash_Obj.JS2Flash_SetValue(val);
 }

 function getMovieName(movieName) {
   if (navigator.appName.indexOf("Microsoft") != -1) {
       return window[movieName];
   }
   else {
       return document[movieName];
   }
 }

 function ShowAlert(msg) {
   alert(msg);
 }

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2024-10-23 03:09:45

很简单。使用 document.getElementById('flashgame').JS2Flash_SetValue(msg) ,它的效果就像一个魅力

simple it was. used document.getElementById('flashgame').JS2Flash_SetValue(msg) and it worked like a charm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文