js與flash的交互FLASH連播控制器
更新時(shí)間:2007年08月29日 19:14:19 作者:
該實(shí)例主要實(shí)現(xiàn)了js與flash的交互,運(yùn)行前提是瀏覽器安裝了flash插件!
前段時(shí)間領(lǐng)導(dǎo)提出的一個(gè)問(wèn)題:能否實(shí)現(xiàn)多個(gè)flash的連續(xù)播放?
查了相關(guān)資料并通過(guò)自己的努力,最終實(shí)現(xiàn)了如下一個(gè)簡(jiǎn)單的Flash連續(xù)播放的js腳本。
該功能的實(shí)現(xiàn)實(shí)際上相當(dāng)簡(jiǎn)單,主要是要了解js對(duì)flash控制的接口函數(shù),知道了這些,問(wèn)題的難度馬上就降到了1+1=?的級(jí)別。
var flashs=[
"http://60.210.98.23/theater/flash/2007-07/1436151_1183823655.swf",
"http://www.flashempire.com/theater/flash/2007-08/1300680_1186654843.swf",
"http://60.210.98.23/theater/flash/2007-05/1178503513_chinese.swf",
"http://60.210.98.23/theater/flash/2007-07/1192848_1183734914.swf"
];
function makeFlashStr(url){
return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400" id="swf">\
<param name="bgcolor" value="#ffffff">\
<param name="movie" value="'+url+'">\
<param name="quality" value="high">\
<embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed></object>';
}
var curFlash=0;
var flashLen=flashs.length;
var $=function(obj){return document.getElementById(obj)}
//判斷是否需要播放下一個(gè)flash
function updateMovie(){
var swf=$("swf");
var swf_container=$("swfcontain");
if(swf.PercentLoaded()==100){
var totalFrames;
//IE與標(biāo)準(zhǔn)瀏覽器的差別
try{ //For Opera/FF
totalFrames=swf.TotalFrames();
}catch(e){ //For IE
totalFrames=swf.TotalFrames;
}
var curFrame=swf.CurrentFrame()+1;
var isPlay=swf.IsPlaying();
if(totalFrames==curFrame){
swfcontain.innerHTML=makeFlashStr(flashs[++curFlash%flashLen]);
$("flashList").selectedIndex=curFlash;
}
//調(diào)試信息
$("curFlash").value=flashs[curFlash%flashLen];
$("totalFrames").value=totalFrames;
$("curFrame").value=curFrame;
$("playStatu").value=(isPlay?"播放中"+[".","..","..."][parseInt(curFrame/10)%3]:"停止");
}else{
//調(diào)試信息
$("curFlash").value=flashs[curFlash%flashLen];
$("totalFrames").value="Loading Flash";
$("curFrame").value="Loading Flash";
$("playStatu").value="Loading Flash";
}
setTimeout("updateMovie()",100);
}
//手工指定要播放的flash
function setMovie(index){
curFlash=index;
$("swfcontain").innerHTML=makeFlashStr(flashs[index]);
}
window.onload=function(){
var sel=$("flashList");
//初始化并生成flash列表
for(var i=0;i<flashLen;i++){
$("flashList").add(new Option(flashs[i],i));
}
setMovie(0); //播放第一個(gè)flash
//循環(huán)檢測(cè)并更新flash
setTimeout("updateMovie()",10);
}
另奉上js與flash的操作接口函數(shù),一方面自己備忘,另一方面希望對(duì)這個(gè)程序有興趣的朋友能有所幫助。
--------------------------------------------------------------------------------
可控制Flash Player的Javascript方法一覽表:
Play() ---------------------------------------- 播放動(dòng)畫
StopPlay()------------------------------------停止動(dòng)畫
IsPlaying()----------------------------------- 動(dòng)畫是否正在播放
GotoFrame(frame_number)---------------- 跳轉(zhuǎn)到某幀
TotalFrames()------------------------------- 獲取動(dòng)畫總幀數(shù)
CurrentFrame()------------------------------回傳當(dāng)前動(dòng)畫所在幀數(shù)-1
Rewind()-------------------------------------使動(dòng)畫返回第一幀
SetZoomRect(left,top,right,buttom)-------放大指定區(qū)域
Zoom(percent)------------------------------改變動(dòng)畫大小
Pan(x_position,y_position,unit)------------使動(dòng)畫在x,y方向上平移
PercentLoaded()----------------------------返回動(dòng)畫被載入的百分比
LoadMovie(level_number,path)----------- 加載動(dòng)畫
TGotoFrame(movie_clip,frame_number)- movie_clip跳轉(zhuǎn)到指定幀數(shù)
TGotoLabel(movie_clip,label_name)------ movie_clip跳轉(zhuǎn)到指定標(biāo)簽
TCurrentFrame(movie_clip)--------------- 回傳movie_clip當(dāng)前幀-1
TCurrentLabel(movie_clip)-----------------回傳movie_clip當(dāng)前標(biāo)簽
TPlay(movie_clip)---------------------------播放movie_clip
TStopPlay(movie_clip)----------------------停止movie_clip的播放
GetVariable(variable_name)-----------------獲取變量
SetVariable(variable_name,value)-----------變量賦值
TCallFrame(movie_clip,frame_number)---call指定幀上的action
TCallLabel(movie_clip,label)----------------call指定標(biāo)簽上的action
TGetProperty(movie_clip,property)--------獲取movie_clip的指定屬性
TSetProperty(movie_clip,property,number)-設(shè)置movie_clip的指定屬性
前段時(shí)間領(lǐng)導(dǎo)提出的一個(gè)問(wèn)題:能否實(shí)現(xiàn)多個(gè)flash的連續(xù)播放?
查了相關(guān)資料并通過(guò)自己的努力,最終實(shí)現(xiàn)了如下一個(gè)簡(jiǎn)單的Flash連續(xù)播放的js腳本。
該功能的實(shí)現(xiàn)實(shí)際上相當(dāng)簡(jiǎn)單,主要是要了解js對(duì)flash控制的接口函數(shù),知道了這些,問(wèn)題的難度馬上就降到了1+1=?的級(jí)別。
復(fù)制代碼 代碼如下:
var flashs=[
"http://60.210.98.23/theater/flash/2007-07/1436151_1183823655.swf",
"http://www.flashempire.com/theater/flash/2007-08/1300680_1186654843.swf",
"http://60.210.98.23/theater/flash/2007-05/1178503513_chinese.swf",
"http://60.210.98.23/theater/flash/2007-07/1192848_1183734914.swf"
];
function makeFlashStr(url){
return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400" id="swf">\
<param name="bgcolor" value="#ffffff">\
<param name="movie" value="'+url+'">\
<param name="quality" value="high">\
<embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed></object>';
}
var curFlash=0;
var flashLen=flashs.length;
var $=function(obj){return document.getElementById(obj)}
//判斷是否需要播放下一個(gè)flash
function updateMovie(){
var swf=$("swf");
var swf_container=$("swfcontain");
if(swf.PercentLoaded()==100){
var totalFrames;
//IE與標(biāo)準(zhǔn)瀏覽器的差別
try{ //For Opera/FF
totalFrames=swf.TotalFrames();
}catch(e){ //For IE
totalFrames=swf.TotalFrames;
}
var curFrame=swf.CurrentFrame()+1;
var isPlay=swf.IsPlaying();
if(totalFrames==curFrame){
swfcontain.innerHTML=makeFlashStr(flashs[++curFlash%flashLen]);
$("flashList").selectedIndex=curFlash;
}
//調(diào)試信息
$("curFlash").value=flashs[curFlash%flashLen];
$("totalFrames").value=totalFrames;
$("curFrame").value=curFrame;
$("playStatu").value=(isPlay?"播放中"+[".","..","..."][parseInt(curFrame/10)%3]:"停止");
}else{
//調(diào)試信息
$("curFlash").value=flashs[curFlash%flashLen];
$("totalFrames").value="Loading Flash";
$("curFrame").value="Loading Flash";
$("playStatu").value="Loading Flash";
}
setTimeout("updateMovie()",100);
}
//手工指定要播放的flash
function setMovie(index){
curFlash=index;
$("swfcontain").innerHTML=makeFlashStr(flashs[index]);
}
window.onload=function(){
var sel=$("flashList");
//初始化并生成flash列表
for(var i=0;i<flashLen;i++){
$("flashList").add(new Option(flashs[i],i));
}
setMovie(0); //播放第一個(gè)flash
//循環(huán)檢測(cè)并更新flash
setTimeout("updateMovie()",10);
}
另奉上js與flash的操作接口函數(shù),一方面自己備忘,另一方面希望對(duì)這個(gè)程序有興趣的朋友能有所幫助。
--------------------------------------------------------------------------------
可控制Flash Player的Javascript方法一覽表:
Play() ---------------------------------------- 播放動(dòng)畫
StopPlay()------------------------------------停止動(dòng)畫
IsPlaying()----------------------------------- 動(dòng)畫是否正在播放
GotoFrame(frame_number)---------------- 跳轉(zhuǎn)到某幀
TotalFrames()------------------------------- 獲取動(dòng)畫總幀數(shù)
CurrentFrame()------------------------------回傳當(dāng)前動(dòng)畫所在幀數(shù)-1
Rewind()-------------------------------------使動(dòng)畫返回第一幀
SetZoomRect(left,top,right,buttom)-------放大指定區(qū)域
Zoom(percent)------------------------------改變動(dòng)畫大小
Pan(x_position,y_position,unit)------------使動(dòng)畫在x,y方向上平移
PercentLoaded()----------------------------返回動(dòng)畫被載入的百分比
LoadMovie(level_number,path)----------- 加載動(dòng)畫
TGotoFrame(movie_clip,frame_number)- movie_clip跳轉(zhuǎn)到指定幀數(shù)
TGotoLabel(movie_clip,label_name)------ movie_clip跳轉(zhuǎn)到指定標(biāo)簽
TCurrentFrame(movie_clip)--------------- 回傳movie_clip當(dāng)前幀-1
TCurrentLabel(movie_clip)-----------------回傳movie_clip當(dāng)前標(biāo)簽
TPlay(movie_clip)---------------------------播放movie_clip
TStopPlay(movie_clip)----------------------停止movie_clip的播放
GetVariable(variable_name)-----------------獲取變量
SetVariable(variable_name,value)-----------變量賦值
TCallFrame(movie_clip,frame_number)---call指定幀上的action
TCallLabel(movie_clip,label)----------------call指定標(biāo)簽上的action
TGetProperty(movie_clip,property)--------獲取movie_clip的指定屬性
TSetProperty(movie_clip,property,number)-設(shè)置movie_clip的指定屬性
相關(guān)文章
圖文演示Flash+ASP實(shí)現(xiàn)用戶登錄/注冊(cè)程序
圖文演示Flash+ASP實(shí)現(xiàn)用戶登錄/注冊(cè)程序...2007-12-12Flash中常用到的ActionScript控制語(yǔ)句用法
Flash中常用到的ActionScript控制語(yǔ)句用法...2007-03-03AS3.0 實(shí)例學(xué)習(xí) 熟悉AS3的package,以及多個(gè)package之間的相互通信
AS3.0 實(shí)例學(xué)習(xí) 熟悉AS3的package,以及多個(gè)package之間的相互通信...2007-12-12SWF自適應(yīng)布局技巧 (Rapid Flash Development)快速Flash開發(fā)
當(dāng)我們開發(fā)全站式Flash應(yīng)用時(shí),希望呈現(xiàn)一個(gè)鋪滿瀏覽器屏幕的Flash.2008-12-12