本文介绍了ExternalInterface.call() 没有得到返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回 div 的innerHTML 的Javascript 函数.我试图从 Actionscript 调用这个函数并存储返回值.我知道 Javascript 函数正在被调用,因为有一个显示返回数据的警报,但是返回到 Actionscript 的数据为空.我不确定是什么原因造成的.这是我尝试执行的操作的代码示例:

I have a Javascript function that returns the innerHTML of a div. I am attempting to call this function from Actionscript and store the return value. I know that the Javascript function is being called because there is an alert that displays the return data, The data that is returned to Actionscript, however, is null. I am not sure what is causing this. Here is a code example of what I am attempting to do:

Javascript:
function JSFunc () {
     var x = document.getElementById("myDiv");
     alert(x.innerHTML);
     return x.innerHTML;
}

Actionscript:
import flash.external.*;
if (ExternalInterface.available) {
     var retData:Object = ExternalInterface.call("JSFunc");
     if(retData != null) {
          textField.text = retData.toString();
     } else {
          textField.text = "Returned Null";
     }
} else {
     textField.text = "External Interface not available";
}

就像我之前说的,警报显示了 div 的内容,但文本字段中的文本总是返回空",这意味着 ExternalInterface 可用.我应该补充一点,我只能在 IE7 和 IE8 中对此进行测试.任何关于做什么的建议将不胜感激.

Like I said earlier, the alert shows up with the contents of the div but the text in the textfield is always "Returned Null", meaning that the ExternalInterface is available. I should add that I can only test this in IE7 and IE8. Any advice on what to do would be much appreciated.

推荐答案

问题的根源在于我用来嵌入 Flash 电影的对象标记.我使用的是遵循此示例的标签 http://www.w3schools.com/flash/flash_inhtml.asp,我将其更改为与此示例匹配:http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_4150 然后我确保将 id 添加到对象并且一切正常.

The source of the problem that I have been having has to do the object tag that I was using to embed the flash movie. I was using a tag that followed this example http://www.w3schools.com/flash/flash_inhtml.asp, I changed it to match this example: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_4150 and then I made sure that I added id to the object and everything worked.

这篇关于ExternalInterface.call() 没有得到返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 11:35