Flash JavaScript (Ajax)在IE中不起作用?

时间:2022-08-25 18:30:30


I made a Flash application that add's content to a page using JavaScript(Ajax). But strangely enough it doesn't work in IE(7 nor 8). It works fine in Chrome and FireFox.
The JavaScript function is (probably) not the problem, because when I insert javascript:functionName(id); in my browser it works.
In my Flash I use the JavaScript on a button with the following code:

我制作了一个Flash应用程序,使用JavaScript(Ajax)将内容添加到页面中。但奇怪的是,它在IE(7或8)中不能用,在Chrome和FireFox中也可以用。JavaScript函数(可能)不是问题所在,因为当我插入JavaScript:functionName(id)时;在我的浏览器中,它可以工作。在我的Flash中,我在按钮上使用JavaScript,代码如下:

getURL("javascript:functionName(id);");

I suppose that, that's a good way to use it?

我想这是一个很好的使用方法?

But strangely enough nothing works in Flash, not even if I replace the code with alert('hello my friend');(maybe he's not my friend?).

但奇怪的是,在Flash中什么都不能用,即使我用alert(“你好,我的朋友”)替换代码也不行(也许他不是我的朋友?)。

Could someone help me out and tell me what may be causing the problem?
Thanks in advance!

谁能帮我一下,告诉我是什么引起了这个问题?提前谢谢!

1 个解决方案

#1


3  

You should be using AS ExternalInterface to communicate with JS, have a look on this: http://www.nelsond8.com/?p=515#more (here I'm using swfobject built in method swfobject.getObjectById, if you are not using swfObject replace this line with document.getElementById)

您应该使用ExternalInterface来与JS通信,请查看以下内容:http://www.nelsond8.com/?更多(这里我使用的是swfobject方法中内置的swfobject。getObjectById,如果不使用swfObject,用document.getElementById替换这一行)

If you are using AS2, you could do something like this:

如果你使用AS2,你可以做如下的事情:

<script type="text/javascript">
function myFunction(id)
{
alert('hello my friend');       
return 'hello my friend';

}
</script>

AS2:

AS2:

import flash.external.*;

btn.onPress = function() 
    {
        var jsReply:String = String(ExternalInterface.call("myFunction", "01"));

        getURL("jsReply");

        trace(jsReply);
    }

And here is the externalInterface reference page for AS2: http://flash-reference.icod.de/

下面是AS2的外部接口参考页面:http://flash-reference.icod.de/。

#1


3  

You should be using AS ExternalInterface to communicate with JS, have a look on this: http://www.nelsond8.com/?p=515#more (here I'm using swfobject built in method swfobject.getObjectById, if you are not using swfObject replace this line with document.getElementById)

您应该使用ExternalInterface来与JS通信,请查看以下内容:http://www.nelsond8.com/?更多(这里我使用的是swfobject方法中内置的swfobject。getObjectById,如果不使用swfObject,用document.getElementById替换这一行)

If you are using AS2, you could do something like this:

如果你使用AS2,你可以做如下的事情:

<script type="text/javascript">
function myFunction(id)
{
alert('hello my friend');       
return 'hello my friend';

}
</script>

AS2:

AS2:

import flash.external.*;

btn.onPress = function() 
    {
        var jsReply:String = String(ExternalInterface.call("myFunction", "01"));

        getURL("jsReply");

        trace(jsReply);
    }

And here is the externalInterface reference page for AS2: http://flash-reference.icod.de/

下面是AS2的外部接口参考页面:http://flash-reference.icod.de/。