WEB开发网
开发学院图形图像Flash Flash AS2入门教程第九课第2节:MP3播放器的制作 阅读

Flash AS2入门教程第九课第2节:MP3播放器的制作

 2010-07-08 00:00:00 来源:WEB开发网   
核心提示: 快进快退按钮,在当前已播放长度的基础上加上或减去5秒,重新播放歌曲 kj_btn.onRelease=function(){wmp3.stop();kjd=dqcd+5;wmp3.start(kjd);}kt_btn.onRelease=function(){wmp3.stop();ktd=dq

快进快退按钮,在当前已播放长度的基础上加上或减去5秒,重新播放歌曲

kj_btn.onRelease=function(){ 
wmp3.stop(); 
kjd = dqcd + 5; 
wmp3.start(kjd); 
} 
kt_btn.onRelease=function(){ 
wmp3.stop(); 
ktd = dqcd - 5; 
wmp3.start(ktd); 
} 

下面的声道控制,在Sound类,的setPan()方法可以设置声音的声道,值为0-100,0声音将完全由左声道播出,而100则完全由右声道播出. 当移动声道控制上滑块,放开时根据滑块的位置设置声道的值.

sd_mc.sdhk_mc.onPress = function(){ 
startDrag(this,true,0,0,sd_mc._width-this._width/2,0); 
} 
sd_mc.sdhk_mc.onRelease = function(){ 
stopDrag(); 
sdz = (this._x)/sd_mc._width*100; 
wmp3.setPan(sdz); 
}

音量控制,在Sound类中可以使用setVolume()方法设置声音的音量,值为0-100,当移动音量控制上滑块,放开时根据滑块的位置设置音量的值.

yl_mc.ylhk_mc.onPress = function(){ 
startDrag(this,true,0,0,yl_mc._width-this._width/2,0); 
} 
yl_mc.ylhk_mc.onRelease = function(){ 
stopDrag(); 
ylz = (this._x)/yl_mc._width*100; 
wmp3.setVolume(ylz); 
} 

OK,现在真正的完全完成了,静下心来欣赏音乐吧.

完整的代码:

song_mc._yscale = 0;
var wmp3:Sound = new Sound();
var zcd;
var dqcd;
var ztd =0;
var jd;
var rul:String;
var sdz;
var ylz;
jdk_mc.jdt_mc._xscale = 0;
gbhl();
ply_btn.onRelease = function(){
        if(ztd ==0){
        rul = RUL_txt.text;
        if(rul){
        jdk_mc.jdt_mc._xscale = 0;
        wmp3.loadSound(rul,true);
        wmp3.start();
        mp3pl(wmp3);
}
}else {
        wmp3.start(ztd);
        mp3pl(wmp3);
}
}
jdk_mc.onRelease= function(){
        var djd = _xmouse - jdk_mc._x;
        var kjd = djd/jdk_mc._width*zcd;
        wmp3.stop();
        wmp3.start(kjd);
}
function mp3pl(mp3){
onEnterFrame = function(){
                zcd = mp3.duration/1000;
                dqcd = mp3.position/1000;
                zcd_txt.text = Math.floor(zcd);
                dqcd_txt.text = Math.floor(dqcd);
                jd = dqcd/zcd*100;
                jdk_mc.jdt_mc._xscale = jd;
                if(dqcd!=zcd){
                for(i=1;i<6;i++){
                        gb_mc = eval("gb"+i);
            gb_mc._yscale =mp3.getVolume()/2+ random(mp3.getVolume()/2);
                }
                
                }
        }
}
jmdbtn_mc.onRelease = function(){
        if(song_mc._yscale > 0){
                song_mc._yscale = 0;
        }else {
        song_mc._yscale=100;
}
}
song_mc.song1_mc.onRelease = function(){
        RUL_txt.text ="http://www.yuelin.net/%E5%9B%BD%E5%AE%B6160.mp3";
        song_mc._yscale=0;
}
song_mc.song2_mc.onRelease = function(){
        RUL_txt.text ="http://lfg.ourivy.com/sjweb/enjoyment/music/tiany.mp3";
        song_mc._yscale=0;
}
song_mc.song3_mc.onRelease = function(){
        RUL_txt.text ="http://xuegong.zhbit.com/jx/edit/uploadfile/2008223213733227.mp3";
        song_mc._yscale=0;
}
song_mc.song4_mc.onRelease = function(){
        RUL_txt.text ="http://www.lygmlr.gov.cn/music/%E7%94%BB%E5%BF%83.mp3";
        song_mc._yscale=0;
}
song_mc.song5_mc.onRelease = function(){
        RUL_txt.text ="http://1968.wzeg.com/UploadFiles/2008-6/436743781.mp3";
        song_mc._yscale=0;
}
song_mc.song6_mc.onRelease = function(){
        RUL_txt.text ="http://211.155.30.36:8089/music/Audio/6.mp3";
        song_mc._yscale=0;
}
function gbhl(){
        for(i=1;i<6;i++){
        gb_mc = eval("gb"+i);
    gb_mc._yscale = 0;
}
}
stop_btn.onRelease=function(){
        wmp3.stop();
        ztd = 0;
        delete onEnterFrame;
        gbhl();
}
zd_btn.onRelease =function(){
        ztd = dqcd;
        wmp3.stop();
        delete onEnterFrame;
        gbhl();
}
kj_btn.onRelease=function(){
        wmp3.stop();
        kjd = dqcd + 5;
        wmp3.start(kjd);
}
kt_btn.onRelease=function(){
        wmp3.stop();
        ktd = dqcd - 5;
        wmp3.start(ktd);
}
sd_mc.sdhk_mc.onPress = function(){
        startDrag(this,true,0,0,sd_mc._width-this._width/2,0);
                        }
sd_mc.sdhk_mc.onRelease = function(){
        stopDrag();
        sdz = (this._x)/sd_mc._width*100;
        wmp3.setPan(sdz);
}
yl_mc.ylhk_mc.onPress = function(){
        startDrag(this,true,0,0,yl_mc._width-this._width/2,0);
        }
yl_mc.ylhk_mc.onRelease = function(){
        stopDrag();
        ylz = (this._x)/yl_mc._width*100;
        wmp3.setVolume(ylz);
        } 

上一页  2 3 4 5 6 7 

Tags:Flash AS 入门教程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接