FlashVars 或外部接口

发布于 2024-09-09 03:52:32 字数 155 浏览 2 评论 0原文

到目前为止,在极少数需要与 HTML 进行通信的情况下,我一直在使用ExternalInterface。

  • FlashVars 被认为是更好/更差还是更新/旧的实践?
  • 或者什么时候使用其中之一?我应该遵循什么逻辑来帮助我决定使用哪一个?

I've been using ExternalInterface up until now in the rare cases I needed to communicate with HTML.

  • Is FlashVars considered a better/worse or newer/older practice?
  • or when do you use one or the other? What's the logic that I should follow to help me decide which one to use?

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

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

发布评论

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

评论(1

来日方长 2024-09-16 03:52:32

FlashVars 没有好坏之分。只是不同而已。它允许您在加载时将一些数据传递到您的 swf。如果您需要的只是最初向 swf 传递一些上下文,那么 FlashVars 就是您想要的。

现在,如果您需要 swf 与其主机(在大多数情况下是可以运行 Javascript 的 Web 浏览器)之间进行更多交互,ExternalInterface 可以为您提供帮助。

如果要将数据从swf传递到主机,请从AS端使用ExternalInterface.call并在html上设置相应的JS函数。如果通信以相反的方式进行,请从 AS 端使用ExternalInterface.addCallback,并使用一个 JS 函数在您的 html 上调用此回调。当然,如果需要的话,你可以同时使用call和addCallback。不过,大多数时候,我只使用ExternalInterface.call,因为我主要使用这种机制来调用谷歌分析或其他一些跟踪系统。

ExternalInterface 的一个重要方面是,要使其成功,必须加载 swf 和处理通信的 JS 代码。如果您仔细考虑一下,这是显而易见的,但如果您不考虑这一点,则可能会导致问题。也就是说,如果您从 JS 调用一个尚未在 swf 中添加为回调的函数,那么...它不会被调用。反之亦然,尽管这种情况在实践中更为罕见。

FlashVars is not better or worse. It's just different. It allows you to pass some data to your swf at load time. If all you need is to pass you swf some context initially, FlashVars is what you want.

Now, if you require more interaction between your swf and it's host (which in most cases is a web browser that can run Javascript), ExternalInterface is there to help.

If you want to pass data from the swf to the host, use ExternalInterface.call from the AS side and set a corresponding JS function on your html. If the communication goes the other way round, use ExternalInterface.addCallback from the AS side and have a JS function that invokes this callback on your html. Of course, you can use both call and addCallback if you need it. Most of the times, though, I only use ExternalInterface.call, since I use this mechanism mostly for calling google analytics or some other tracking system.

An important aspect of ExternalInterface is that for it to succeed, both your swf and the JS code that handles the communication have to be loaded. This is obvious if you think about it for a second, but could lead to problems if you don't account for it. That is, if from JS you call a function that hasn't yet been added as a callback in your swf, well... it won't be called. The same is true the other way round, though it's more rare in practice.

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