【摘 要】本文利用javascript腳本語言,設(shè)計(jì)并實(shí)現(xiàn)了一個(gè)網(wǎng)頁版的Flash播放器。該播放器可實(shí)現(xiàn)網(wǎng)頁中Flash動(dòng)畫的播放、停止、暫停和快進(jìn)等功能。使用戶能更好地控制網(wǎng)頁中Flash動(dòng)畫的播放。
【關(guān)鍵詞】Javascript;Flash;播放器;網(wǎng)頁
1.引言
在用戶瀏覽網(wǎng)頁時(shí),網(wǎng)頁中的Flash動(dòng)畫(格式一般為swf)通常是自動(dòng)播放的。瀏覽者是無法控制的,比如暫停、快進(jìn)或重播等。這往往會(huì)影響用戶瀏覽網(wǎng)頁時(shí)的體驗(yàn)。本文實(shí)現(xiàn)了一個(gè)網(wǎng)頁版的Flash播放器,該網(wǎng)頁版Flash播放器能對(duì)網(wǎng)頁中的Flash播放進(jìn)行深度控制。
2.Flash播放器的實(shí)現(xiàn)
Flash播放器的控制代碼用javascript實(shí)現(xiàn),主要通過編寫相應(yīng)的函數(shù)控制flash動(dòng)畫的播放、暫停和快進(jìn)等。該代碼編寫到一個(gè)腳本文件myFlash.js中,詳細(xì)代碼如下[1][2][3]。
function Flash_embedSWF(srcURL,swfbgColor){
var defaultColor = (document.
bgColor != 1) ? document.bgColor“#ffffff”;
var bgcolor =(swfbgColor !
= 1) ? 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 “快進(jìn)”:
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.TotalFrames;
}
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.TotalFrames;
}
break;
}
}
接著制作一個(gè)簡(jiǎn)單的靜態(tài)網(wǎng)頁,調(diào)用上面的函數(shù)實(shí)現(xiàn)對(duì)Flash文件的控制。網(wǎng)頁代碼如下所示[4]。
position:absolute;top:320px;
background:darkviolet;left:10px;
font-size:10px;border:1 solid #cccccc
inset;width:300px;height:
15px;z-index:1;\">P
運(yùn)行結(jié)果如圖1所示。
3.結(jié)束語
本文利用javascript腳本語言,設(shè)計(jì)并實(shí)現(xiàn)了一個(gè)網(wǎng)頁版的Flash播放器。該播放器可實(shí)現(xiàn)網(wǎng)頁中Flash動(dòng)畫的播放、停止、暫停和快進(jìn)等功能。使用戶能更好地控制網(wǎng)頁中Flash動(dòng)畫的播放。這大大提高了用戶瀏覽網(wǎng)頁Flash動(dòng)畫的用戶體驗(yàn)。
參考文獻(xiàn):
[1]張孝祥,張紅梅,JavaScript網(wǎng)頁開發(fā)[M].北京:清華大學(xué)出版社,2004.1.
[2]周瑞.從零開始學(xué)Javascript[M].北京:電子工業(yè)出版社,2011.1.
[3]周愛民.Javascript語言精髓與編程實(shí)踐[M].北京:電子工業(yè)出版社,2008.3.
[4]林振榮,王煒立.ASP語言程序設(shè)計(jì)[M].北京:清華大學(xué)出版社,2009.12.
作者簡(jiǎn)介:趙超(1983—),男,碩士研究生,助教,研究方向:計(jì)算機(jī)技術(shù)與應(yīng)用。