在一个更抽象的水平,那么一个previous问题,在我的经验,有三种方法可以从嵌入的.swf使用AS3调用的HTML页面的JavaScript函数。ExternalInterface的中,fscommand和navigateToURL
On a more abstract level then a previous question, in my experience there are 3 ways to call a javascript function on an html page from an embedded .swf using AS3: ExternalInterface, fscommand, and navigateToURL.
让我们来比较和对比这些方法(或者其他人我还没有上市),并谈谈各的优点和缺点 - 现在,ExternalInterface的的似乎的喜欢的方式去在灵活性方面,但是不是所有的情况呢?是否有执行速度之类的东西方面具体的好处?我很好奇 - ?我们怎么觉得
Let's compare and contrast these methods (and maybe others I haven't listed) and talk about the pros and cons of each - right now, ExternalInterface seems like the way to go in terms of flexibility, but is it right for all situations? Are there concrete benefits in terms of execution speed or anything like that? I'm curious - what do we think?
推荐答案ExternalInferface是为了让JS和Flash之间更容易沟通,所以它好好尝试一下真正意义的使用别的。通常的做法是通过调用一些JS前评估ExternalInterface.available属性的值,以检查其可用的第一个。这个属性告诉你,如果要在其中调用一些JS的SWF是一个容器,提供了一个外部接口内。 。换句话说,如果使用ExternalInterface的正常工作。如果其不可用,则只需使用flash.sendToUrl。切勿使用fscommand(),因为它使用VBScript和可能导致与其他VBScript的冲突在页面上。此外,你只能发送一个参数字符串的fscommand并且必须对JS一边拆呢。
ExternalInferface was created to make communication between JS and Flash easier, so it doens't really make sense to use anything else. Common practice is to check if its available first by evaluating the value of the ExternalInterface.available property before making a call to some JS. This property tells you if the SWF in which you want to call some JS from is inside a container that offers an external interface. In otherwords, if using ExternalInterface will work. If its not available then just use flash.sendToUrl. Never use fscommand() as it uses VBScript and can cause conflicts with other VBScript on a page. Additionally, you can only send one argument string with fscommand and have to split it on the JS side.
更多推荐
ActionScript3的JavaScript的通信:最佳实践
发布评论