如何捕获 Flash 影片成功加载时的事件触发?
我目前正在使用 jQuery 以及 swfObject 将 swf 影片动态嵌入到我的网页中。
我目前在将 immem 的音乐播放器嵌入我的网页时遇到问题,因为他们的嵌入代码没有任何加载屏幕。 因此,当我使用 swfObject 替换元素时,该区域通常会是空白的。 在最坏的情况下,这意味着用户不会知道嵌入歌曲正在加载。
因此,我试图找出加载闪存后绑定事件的方法。 因为我的计划是将具有巨大 z-index
的图像放在顶部,并使用此触发器来隐藏图像。 我想我尝试过使用 $('#embed').load(function(){ ... });
,但没有成功。
有人对此有任何解决方案吗? 我只是想知道这是否可能,因为我不想使用闪存进行黑客攻击并尝试将“加载程序”添加到闪存文件中。
更多说明:为了更清楚地说明,我想将imeem的音乐播放器嵌入到我的网页中。 所以,我真的对flash文件没有任何控制权,即我无法自己创建flash文件。
I'm currently using jQuery, as well as swfObject to dynamically embed the swf movie into my web page.
I currently having a problem on embeding immem's music player into my web page, as their embed code doesn't have any loading screen. So, when I replace the element using swfObject, that area will generally blank. In worst case, it means that user won't know that the embed song is loading.
So, I'm trying to find out the way to bind an event after that flash got loaded. Since my plan would be placing image with huge z-index
on the top and use this trigger to hide the image. I think I've tried to use $('#embed').load(function(){ ... });
, with no luck.
Does somebody have any solution for this? I just wonder if that is possible, since I don't want to get hacking with the flash and try to add 'loader' to the flash file.
Some more note: To make it more clear, I want to embed imeem's music player into my webpage. So, I really don't have any control over the flash file, i.e. I can't create a flash file by myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常,最简单的事情是简单的
,它会在调用处理程序之前等待外部资源完成加载。
但是,如果您使用 swfObject 动态添加嵌入式插件,浏览器将触发 Flash 影片正文的加载(它不知道有关您的插件的任何信息)。
请参阅 http://blog.deconcept.com/swfobject/forum/discussion/271/javascript-onload-event-does-not-reflect-page-load-using-swfobject/ 进行与您类似的讨论。 我最好的猜测是,如果不以某种方式修改原始 swf,您就无法做您想做的事。
Typically the easiest thing to do is plain ol'
<body onload="..."
which would wait for your external resources to finish loading before calling your handler.However, if you're using swfObject to add an embedded plugin dynamically the browser will fire the onload for the body exclusive of your flash movie (it doesn't know anything about your plugin).
See http://blog.deconcept.com/swfobject/forum/discussion/271/javascript-onload-event-does-not-reflect-page-load-using-swfobject/ for a similar discussion to yours. It's my best guess that you cannot do what you want without modifying the original swf in some fashion.
您可以在 Flash 影片中执行此操作。 但是,您将需要对电影进行控制(您可能没有)。
You could do this from within the flash movie. However then you will need to have control over the movie (which you may not have).
请注意,如果您打算用图像或 html 内容遮盖 Flash,则需要 wmode=transparent
Note, you'll need wmode=transparent if you intend to obscure flash with an image or html things
上述使用 window.load() 的解决方案的问题是,如果您的主 swf 仅重 1 kb 但它实际上不显示任何内容(只是作为一个加载附加内容的容器,这通常是 。
我要做的是使用 Actionscript 的ExternalInterface 类,该类允许您的 Flash 播放器与包含 Flash 文件的 html 文件中可用的 javascript 函数进行通信,您可以让您的 flash 文件调用触发的 javascript 函数 一个函数,告诉您的 JavaScript 处理脚本 Flash 已准备就绪。
这样做的好处是,当 JavaScript 接管时,您可以对 Flash 文件中应加载的内容进行所需的精确控制。
有关使用ExternalInterface的更多信息,请参阅:http:// blog.circlecube.com/2008/02/01/actionscript-javascript-communication/
Problem with the above-mentioned solution of using window.load() is it is not useful if your main swf weights only 1 kb but it actually doesn't display anything (just being a container that gets additional content loaded, which is often the case in flash files.
What i would do is use Actionscript 's ExternalInterface class that allows your flash player to communicate with the javascript functions available in the html file which contains the flash file. You could have your flash file call a javascript function that triggers a function that tells your javascript processing script that the flash is ready.
What is nice with this is that you get the exact level of control you need over what should be loaded in the flash file when the javascript takes over.
See this for more info on the use of ExternalInterface: http://blog.circlecube.com/2008/02/01/actionscript-javascript-communication/