SWFOBJECT CurrentFrame Javascript
我在播放当前帧时遇到了挑战。我正在使用 swfobject 版本 2.2。
这是我的脚本:
<script type="text/javascript">
function flashplayer(flashname) {
var flashvars = {};
var params = {};
params.play = "true";
params.menu = "true";
params.scale = "noscale";
params.allowfullscreen = "true";
var attributes = {
id: "flashDiv",
name: "flashDiv"
};
swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", flashvars, params, attributes);
var obj = swfobject.getObjectById("myAlternativeContent");
totalFrames = obj.totalFrames;
$('#duration').html(totalFrames);
currentFrame1 = obj.currentFrame;
$('#current').html(currentFrame1);
obj.addEventListener("onStateChange", "onytplayerStateChange");
}
function onStateChange() {
var obj = swfobject.getObjectById("myAlternativeContent");
currentFrame1 = obj.TcurrentFrame;
$('#current').html(currentFrame1);
}
function stopflash() {
var obj = swfobject.getObjectById("myAlternativeContent");
obj.Stop();
}
function PlayFlash() {
var obj = swfobject.getObjectById("myAlternativeContent");
obj.Play();
}
function FlashRewind() {
var obj = swfobject.getObjectById("myAlternativeContent");
obj.Rewind();
}
</script>
<div id="duration">
1
</div>
<div id="current">
1
</div>
<input onclick="flashplayer('../../Video/test.swf');" type="button" style="width: 300px"
value="play flash" /><br />
提前致谢。
I am having a challenge getting the current frame playing. I am using swfobject ver 2.2.
Here is my script:
<script type="text/javascript">
function flashplayer(flashname) {
var flashvars = {};
var params = {};
params.play = "true";
params.menu = "true";
params.scale = "noscale";
params.allowfullscreen = "true";
var attributes = {
id: "flashDiv",
name: "flashDiv"
};
swfobject.embedSWF(flashname, "myAlternativeContent", "800", "600", "9.0.0", flashvars, params, attributes);
var obj = swfobject.getObjectById("myAlternativeContent");
totalFrames = obj.totalFrames;
$('#duration').html(totalFrames);
currentFrame1 = obj.currentFrame;
$('#current').html(currentFrame1);
obj.addEventListener("onStateChange", "onytplayerStateChange");
}
function onStateChange() {
var obj = swfobject.getObjectById("myAlternativeContent");
currentFrame1 = obj.TcurrentFrame;
$('#current').html(currentFrame1);
}
function stopflash() {
var obj = swfobject.getObjectById("myAlternativeContent");
obj.Stop();
}
function PlayFlash() {
var obj = swfobject.getObjectById("myAlternativeContent");
obj.Play();
}
function FlashRewind() {
var obj = swfobject.getObjectById("myAlternativeContent");
obj.Rewind();
}
</script>
<div id="duration">
1
</div>
<div id="current">
1
</div>
<input onclick="flashplayer('../../Video/test.swf');" type="button" style="width: 300px"
value="play flash" /><br />
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速浏览一下,我发现您的代码存在三个问题。
通过在属性对象中指定 ID 和名称,您可以为新创建的
您尝试在
swfobject.embedSWF
之后立即使用swfobject.getObjectById
。但是,这可能不起作用,因为在调用 swfobject.getObjectById 之前嵌入可能无法完成。 (顺便说一句,仅静态发布需要getObjectById
;使用动态发布时,使用标准getElementById
就可以了)您没有指定快速安装参数,因此您的 SWFObject 语法无效。请改用此选项:
.
。
#1 和 #2 的解决方案是使用 SWFObject 的的引用,使您能够避免进行
callback
功能。这有助于确保在嵌入成功之前不会调用 DOM 函数,从而有助于计时。它还提供对嵌入swfobject.getObjectById
调用。请记住,您可能仍然会遇到时间问题;嵌入页面后,就会调用 SWFObject 的回调 - 这并不意味着 SWF 已完成加载。
您可以通过结合 JavaScript
setInterval
检查 Flash Player 的PercentLoaded
方法来检查 SWF 的加载状态。At a quick glance, I see three problems with your code.
By specifying an ID and name in your attributes object, you're assinging a name to the newly created
<object>
. This meansswfobject.getObjectById("myAlternativeContent")
won't work, because you've renamed the<object>
to "flashDiv". You should useswfobject.getObjectById("flashDiv")
instead.You're trying to use
swfobject.getObjectById
immediately afterswfobject.embedSWF
. However this probably won't work, because the embed might not be completed beforeswfobject.getObjectById
is invoked. (BTW,getObjectById
is only needed for static publishing; when using dynamic publishing, it's ok to use the standardgetElementById
)You're not specifying the express install parameter, so your SWFObject syntax is invalid. Use this instead:
.
.
A solution to #1 and #2 is to use SWFObject's
callback
feature. This helps with timing by ensuring you won't invoke your DOM functions until the embed is successful. It also provides a reference to the embedded<object>
which enables you to avoid making theswfobject.getObjectById
call.Bear in mind you may still encounter timing issues; SWFObject's callback is invoked as soon as the
<object>
is embedded in the page -- it doesn't mean the SWF has finished loading.You can check the SWF's loading status by checking Flash Player's
PercentLoaded
method combined with a JavaScriptsetInterval
.