JavaScript 和 SWF 通信
我有一个相当大的交互式 swf 文件,并且该文件使用 SWFObject 嵌入到我的 HTML 中。我可以通过 JavaScript 与 swf 进行通信,并且运行良好。但它没有预加载器,因为文件很大,我想显示加载图像或 swf,当文件完全加载时,使用 JavaScript 显示我的播放按钮。
如果文件已完全加载,我该如何理解?
我尝试了很多解决方案,但没有一个成功。首先,我尝试在 Flash 中创建预加载器并加载外部 swf,然后使用外部接口在完成事件时向 JavaScript 发送消息,它有效,但我无法再通过 JS 与主 swf 动作脚本进行通信。
我发现一些 JavaScript 库应该在文件加载时触发事件,但在加载成功时(swf 文件在那里并开始加载)就会发生这种情况。
I have a sizeable interactive swf file and the file is embedded to my HTML using SWFObject. I can communicate with the swf by JavaScript and it works perfectly. But it has no preloader and because the file is big I want to show a loading image or swf and when the file is loaded completely show my play button using JavaScript.
How can I understand, if the file is loaded completely?
I tried bunch of solutions but none of them was successful. First, I tried to create a preloader in Flash and load my external swf then send a message to JavaScript on complete event using externalinterface, it worked, but I couldn't communicate to the main swf Action Scripts by JS anymore.
I found some JavaScript libraries that are supposed to fire an event, when the file is loaded but it happens when the loading is successful (the swf file is there and starts loading).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还强烈建议您将播放/暂停等功能直接合并到 Flash 程序中 - 实际上不需要为此使用 JavaScript!
但是如果你必须使用JS,你可以通过创建一个 内部预加载器,或加载外部预加载器swf 放入同一个应用程序域(如果您不使用 JS,则无需担心应用程序域),或者使用 SWFBridge 在两个单独的 SWF 之间建立双向通信。
如果您希望将所有数据嵌入到一个文件中,则内部预加载器是一种非常巧妙的解决方案 - 代价是必须创建额外的框架,并且必须考虑将类实例准确地放置在 FLA 中的位置(您可以不要使用“嵌入到框架 1”)。
加载到同一应用程序域更加优雅,特别是如果您主要使用 Flash IDE 进行编码(而不是设计),或者无论如何您都有外部数据。另外,这是创建模块化应用程序的好方法。
如果您有 ActionScript 2 SWF 或没有直接可用源代码的旧文件,那么 SWFBridge 确实很好 - 但如果您需要的只是一个简单的预加载器和一些 JavaScript,那么在这种情况下我可能不会使用它。
I would also strongly recommend you incorporate your play/pause, etc., functionality directly into your Flash program - there is really no need to use JavaScript for this!
But if you have to use JS, you could show the load progress by creating an internal preloader, or loading an external swf into the same application domain (whereas if you don't use JS, you don't need to worry about application domains), or using SWFBridge to establish two-way communications between two separate SWFs.
The internal preloader is a pretty neat solution, if you want all of your data embedded into just one file - at the expense of having to create additional frames, and having to think about where exactly to put your class instances in your FLA (you can't use "Embed into frame 1").
Loading into the same application domain is more elegant, especially if you use your Flash IDE mostly for coding (and not design), or if you have external data anyway. Plus, it's a good way to create modular applications.
SWFBridge is really good if you have ActionScript 2 SWFs, or legacy files without directly available source code - but if all you need is a simple preloader and some JavaScript, I would probably not use it in this case.