//t_txt //bg_mc 40 //stop() // txt TextField // bg background // dataArr [str1,str2,...] // loopNum dataArr 循环的次数 var typewriter={} typewriter.main=function(tmc,dataArr,loopNum){ this.container=tmc; this.target = tmc.t_txt; this.target.textColor=0x6666cc; this.target.filters = [new flash.filters.GlowFilter(0xFFFFFF, 1, 2, 2, 32, 1)] //this.target.filters = [new flash.filters.GlowFilter(0x6f89c3, 1, 2, 2, 32, 1)] this.bgMc = tmc.bg_mc; this.dbArr=dataArr; this.loop = loopNum || 1; this.counter = this.loop * this.dbArr.length this.idx = 0; this.textLength = 1; this.textBuffer; //缓存当前打字字符串 this.typeTime=50; this.showTime=2000; //打完后停留时间 this.typeValID; this.showValID; this.initFlag=false; //初始化标志 this.readItem() } typewriter.readItem=function(){ this.textLength =1; this.target.text = "" this.textBuffer = this.dbArr[this.idx=this.idx>this.dbArr.length-1 ? 0 : this.idx]; this.idx++; var w=Math.ceil(this.getTextFieldWidth(this.textBuffer)) if(w>scr.width) w = scr.width this.target._width = w; if(!typewriter.initFlag){ this.container._x=(scr.width-w)/2-15 //if(this.container._x<32) this.container._x=32 this.container._y=scr.height-scr.textBgMc._height-16-32 //this.container._y=scr.textBgMc._height+6 this.initFlag=true; } //var t=new mx.transitions.Tween(this.bgMc, "_width", mx.transitions.easing.Elastic.easeOut, 40, w+30, 1, true); var t=new mx.transitions.Tween(this.bgMc, "_width", mx.transitions.easing.Regular.easeInOut, 40, w+30, 1, true); if(this.showValID) clearInterval(this.showValID) this.typeValID = setInterval(this,"type", this.typeTime); } typewriter.type=function() { this.textLength<=this.textBuffer.length ? this.target.text=substring(this.textBuffer, 1, this.textLength++) : this.nextItem(); } typewriter.nextItem=function() { if(this.typeValID) clearInterval(this.typeValID) if(--this.counter>0){ this.showValID = setInterval(this,"readItem", this.showTime); } } //获取文本域宽度 typewriter.getTextFieldWidth=function (str:String):Number { var txt_fmt:TextFormat= new TextFormat(); txt_fmt.font = "_sans"; txt_fmt.size = 14; txt_fmt.bold = true; var metrics:Object = txt_fmt.getTextExtent(str); return metrics.textFieldWidth; } /* typewriter.main( imgtip_mc, //["可用鼠标中键滚页", "PAGEUP,PAGEDOWN 功能键滚页", "鼠标拖拽内容空白区可以滚页"], ["PAGEUP,PAGEDOWN 功能键滚页"], 1 ) */