网页版Flash播放器的实现
【摘要】本文利用javascript脚本语言,设计并实现了一个网页版的Flash 播放器。
该播放器可实现网页中Flash动画的播放、停止、暂停和快进等功能。
使用户能更好地控制网页中Flash动画的播放。
【关键词】Javascript;Flash;播放器;网页
1.引言
在用户浏览网页时,网页中的Flash动画(格式一般为swf)通常是自动播放的。
浏览者是无法控制的,比如暂停、快进或重播等。
这往往会影响用户浏览网页时的体验。
本文实现了一个网页版的Flash播放器,该网页版Flash播放器能对网页中的Flash播放进行深度控制。
2.Flash播放器的实现
Flash播放器的控制代码用javascript实现,主要通过编写相应的函数控制flash动画的播放、暂停和快进等。
该代码编写到一个脚本文件myFlash.js中,详细代码如下[1、2、3]。
function Flash_embedSWF(srcURL,swfbgColor){
vardefaultColor=(document.bgColor!=null)?document.bgColor:”#ffffff”;
varbgcolor=(swfbgColor!=null)?swfbgColor:defaultColor;
document.writeln(
……+
……+
……+
……+
……+
……+
……+
……);
window.document.flash.Rewind();
}
function buttonClk()
{
switch(event.srcElement.value)
{
case “播放”:
window.document.flash.Play();
break;
case “停止”:
window.document.flash.Rewind();
oButton.style.pixelLeft=10;
break;
case “暂停”:
window.document.flash.stopplay();
break;
case “快进”:
if(window.document.flash.IsPlaying())
window.document.flash.StopPlay();
else
{
window.document.flash.gotoframe(window.document.flash.CurrentFrame()+50);
oButton.style.pixelLeft=10+290*(oPlayer.CurrentFrame()+1)/oPlayer.TotalFrame s;
}
break;
case “快退”:
if(window.document.flash.IsPlaying())
window.document.flash.StopPlay();
else
{
window.document.flash.gotoframe(window.document.flash.CurrentFrame()-50);
oButton.style.pixelLeft=10+290*(oPlayer.CurrentFrame()+1)/oPlayer.TotalFrame s;
}
break;
}
}
接着制作一个简单的静态网页,调用上面的函数实现对Flash文件的控制。
网页代码如下所示[4]。
Flash_embedSWF(“12shengxiao.swf”);
P。