/*================================================================================== scr 字幕的实现,基于lrc的数据 ===================================================================================*/ var scr = new Object(); scr.curStr; scr.curFPS = 30; //实际帧率记录 scr.kalaok = true; scr.txtForeClr = 0xFFFFFF; //字幕扫描前的颜色 scr.txtBackClr = 0xFF00FF; //字幕扫描后的颜色 scr.txtForeBgClr = 0x000000; //字幕扫描前的背景颜色 scr.txtBackBgClr = 0xFFFFFF; //字幕扫描后的背景颜色 scr.depthManager = {fps_mc:1, sound_mc:2, bg_mc:4, con_mc:5, conMask_mc:6, textBg_mc:7, text_mc:8, title_mc:9,imgtip_mc:10,logo_mc:11,begin_mc:12}; scr.status = "PLAY" //PLAY, PAUSE scr.init = function() { sys.reSize() scr.height = sys.stageHeight-44 scr.width = Math.ceil(scr.height/3*4) scr.fontSize = Math.ceil(scr.width/25); if(scr.fontSize<12) scr.fontSize=12; // 保证 minfont >=12 var self = this; this.soundMc = sys.screenMc.createEmptyMovieClip("sound_mc", this.depthManager.sound_mc); this.bgMc = sys.screenMc.createEmptyMovieClip("bg_mc", this.depthManager.bg_mc); this.conMc = sys.screenMc.createEmptyMovieClip("con_mc", this.depthManager.con_mc); this.conMaskMc = sys.screenMc.createEmptyMovieClip("conMask_mc", this.depthManager.conMask_mc); this.textBgMc = sys.screenMc.createEmptyMovieClip("textBg_mc", this.depthManager.textBg_mc); this.textMc = sys.screenMc.createEmptyMovieClip("text_mc", this.depthManager.text_mc); this.titleMc = sys.screenMc.createEmptyMovieClip("title_mc", this.depthManager.title_mc); //sys.setMatrixFilter(this.conMc,"sepia") //sys.drawRectangle(this.conMaskMc, this.width, this.height, 0xFFFFFF, 100); //this.conMc.setMask(this.conMaskMc); //sys.drawRectangle(this.bgMc, this.width, this.height, 0x808080, 100); var th = Math.ceil(scr.height/7.6); if(th<40) th = 40 //minHeight this.textBgMc._y = scr.height - th; this.textBgMc._x = -scr.width sys.drawRectangle(this.textBgMc, 3*scr.width, th, 0, 40); this.logoMc = sys.screenMc.attachMovie("logo_mc","logo_mc", this.depthManager.logo_mc); //this.logoMc.logo_btn._width=scr.width //this.logoMc.logo_btn._height=scr.height-th this.logoMc.logo_btn.onRelease=function(){ getURL("http://www.qingcai.net","_blank"); } this.conMc.createEmptyMovieClip("con", 0); //this.conMc.con.loadMovie("testdata/p.jpg"); this.fpsMc = sys.screenMc.createEmptyMovieClip("fps_mc", this.depthManager.fps_mc); this.fpsMc.fc = 0; this.fpsMc.onEnterFrame = function() { this.fc++; }; setInterval(function () { self.curFPS = self.fpsMc.fc; self.fpsMc.fc = 0; }, 1000); }; /* scr.createSoundLoad=function(){ this.soundLoadMc = sys.screenMc.attachMovie("soundLoad_mc","soundLoad_mc", this.depthManager.soundLoad_mc); } scr.removeSoundLoad=function(){ this.soundLoadMc.removeMovieClip() } */ scr.createBegin=function(){ this.beginMc = sys.screenMc.attachMovie("begin_mc","begin_mc", this.depthManager.begin_mc); this.beginMc._y = Math.floor(scr.height/2) this.beginMc._x = Math.floor(scr.width/2) this.beginMc.play_btn.onRelease = sys.ctrlMc.play_btn.onRelease } scr.removeBegin=function(){ this.beginMc.removeMovieClip() } scr.createImgtip=function(sArr){ var s=sArr[0].toLowerCase() var t=s.substr(s.length-4,4) var r=".jpg|.png|.gif" if(s!=""&&r.indexOf(t)==-1){ this.imgtipMc=sys.screenMc.attachMovie("imgtip_mc","imgtip_mc", this.depthManager.imgtip_mc); typewriter.main(this.imgtipMc,sArr,1) } } scr.removeImgtip=function(){ this.imgtipMc.removeMovieClip() } scr.play = function(){ scr.status = "PLAY" scr.removeBegin(); scr.conMc.pluginMc.play(); run.resume() } scr.pause = function(){ scr.status = "PAUSE" scr.conMc.pluginMc.pause(); run.pause() } scr.stop = function(){ scr.status = "STOP" this.removeTit() this.removeTxt() scr.conMc.pluginMc.pause(); run.pause() } scr.createTit = function(obj, dur) { if(!this.titleMc._name){ this.titleMc = sys.screenMc.createEmptyMovieClip("title_mc", this.depthManager.title_mc); } if (this.titleMc.ti_txt) { return (undefined); } var tu = this.fontSize/3; if(tu<6)tu=6; //保证 minfont >=12 var ta = Math.ceil(tu*4); var tb = Math.ceil(tu*2); var bx = Math.ceil(scr.width/10); //45 var by = Math.ceil(scr.width/5); //90 var tiTxt = this.titleMc.createTextField("ti_txt", 0, bx, by, 1, ta); var arTxt = this.titleMc.createTextField("ar_txt", 1, bx+Math.ceil(tu/4), by+Math.ceil(tu*6), 1, Math.ceil((tu/3)*4)); var alTxt = this.titleMc.createTextField("al_txt", 2, bx+Math.ceil(tu/4), by+Math.ceil(tu*9), 1, Math.ceil((tu/3)*4)); var setFmt = function (target, dat, fi) { target.selectable = false; //target.textColor = 0xFFFFFF; target.autoSize = "left"; target.text = dat; target.setTextFormat(new TextFormat(null, tb, 0x0000FF, true)); target.filters = [fi]; }; var fi; fi = new flash.filters.GlowFilter(16777215, 1, 2, 2, 32, 1); setFmt(tiTxt, obj.ti.split("歌曲:").join(""), fi); tiTxt.setTextFormat(new TextFormat(null, ta, 0xFF00FF, true)); setFmt(arTxt, obj.ar+" ", fi); setFmt(alTxt, obj.al+" ", fi); }; scr.removeTit = function() { if (this.titleMc) { this.titleMc.removeMovieClip(); } }; scr.removeTxt = function() { if (this.textMc) { this.textMc.removeMovieClip(); } }; scr.createTxt = function(str, dur, per) { if(!this.textMc._name){ this.textMc = sys.screenMc.createEmptyMovieClip("text_mc", this.depthManager.text_mc); } if (str == this.curStr) { return (undefined); } this.curStr = str; var bw = Math.ceil(scr.width*0.022); var twMax = scr.width-(bw*2); var tw = this.getTxtWidth(str); var th = Math.ceil((this.fontSize/3)*5); // var tx = bw; var ty = Math.floor(this.textBgMc._y+((this.textBgMc._height-th)/2)); if (tw>twMax) { tw = twMax; } tx = tx+Math.floor((twMax-tw)/2); this.textMc.back_mc.removeMovieClip() this.textMc.fore_mc.removeMovieClip() this.textMc.mask_mc.removeMovieClip() var backMc = this.textMc.createEmptyMovieClip("back_mc", 0); if (per) { var foreMc = this.textMc.createEmptyMovieClip("fore_mc", 1); var maskMc = this.textMc.createEmptyMovieClip("mask_mc", 2); maskMc._x = tx; maskMc._y = ty; sys.drawRectangle(maskMc, tw, th, 0, 100); maskMc.i = (this.curFPS*dur)/1000; maskMc.w = (tw/maskMc.i)*1.15; //maskMc.flag = this.status=="PLAY" ? true:false maskMc.onEnterFrame = function() { if (this.i>0 && scr.status == "PLAY" ) { this._x = this._x+this.w; this.i--; } }; foreMc.setMask(maskMc); var foreTxt = foreMc.createTextField("fore_txt", 0, tx, ty, tw, th); foreTxt.textColor = scr.txtForeClr; } var backTxt = backMc.createTextField("back_txt", 0, tx, ty, tw, th); backTxt.textColor = scr.txtBackClr; var fmt = new TextFormat(); fmt.size = this.fontSize; fmt.bold = true; fmt.align = "center"; var setFmt = function (target, fmt, fi) { target.text = str; target.selectable = false; target.wordWrap = true; target.setTextFormat(fmt); target.setNewTextFormat(fmt); target.filters = [fi]; }; setFmt(backTxt, fmt, new flash.filters.GlowFilter(scr.txtBackBgClr, 1, 2, 2, 32, 1)); setFmt(foreTxt, fmt, new flash.filters.GlowFilter(scr.txtForeBgClr, 1, 2, 2, 32, 1)); }; scr.getTxtWidth = function(str:String):Number { var txt_fmt:TextFormat = new TextFormat() txt_fmt.font = "_sans"; txt_fmt.bold = true; txt_fmt.size = this.fontSize; var metrics:Object = txt_fmt.getTextExtent(str); return metrics.textFieldWidth; }