时间: 2021-07-31 作者:daque
5、场景中帧的分别 把主场景分别为4段轮回的帧构造。
4.2.5.1.第一帧,用来初始化全部变量。
fscommand ("fullscreen", "true"); fscommand ("showmenu", "false"); basedepth = 1; testdepth = 10; menudepth = 2; menux = 118;//菜单的横坐标 menuy = 102;//菜单的横坐标 timebarwidth = 76;//功夫棒的总参谋长度 starttimer = false; typepause = false; nowtimer = gettimer();//计时一次 showtype = "menu"; //表露菜单 menushowfram = true;// 表露后台 backtofram = false;//能否归来到发端界面 loadtext = false;//能否发端倒入原文 level = 1;//难度级别为1 text1 = ""; text2 = ""; textlength = 0; loopnum = 0;
back = false; again = false; timeover = false; typesound = new sound(); typesound.attachsound("type"); errorsound = new sound(); errorsound.attachsound("error"); typesoundplay = true;time = 3; errornum = 0; speednum = 0; choose = new string("normaltext"); inputtext = choose; attachmovie("fram", "fram", basedepth);//表露发端界面包车型的士后台
4.2.5.2 第二帧到第三帧;
第2帧设一个标签“mainloop":
if(loadtext==true) gotoandplay("loadnum");//跳到载入原文的轮回中 if (showfram == false) { fram.removemovieclip();//把后台从屏幕上抹去 removemovieclip (showtype);//把菜单从屏幕上抹去 attachmovie("typespace", "typespace", testdepth); gotoandplay ("typeloop");//跳到熟习的场景中 } else { attachmovie(showtype, showtype, menudepth);//跳到另一个菜单中 } _root[showtype]._x = menux;//树立横坐标 _root[showtype]._y = menuy;//树立横坐标第3帧的代码: gotoandplay("mainloop");
4.2.5.3第3个轮回段:
从第5帧到第6帧。
第5帧标签“typeloop";
if (backtofram == true) { //相应在typespace剪辑上的按钮back的事变归来到发端界面 removemovieclip ("typespace"); gotoandplay (1); } if(again==true)//相应在typespace剪辑上的按钮again的事变 { //场景静止,反复上一次的熟习 removemovieclip("showscores"); text1.scroll=1; text2=""; loopnum=0; again=false; }//以次的代码是用来熟习进程中及时确定,检验和测定咱们分为几个末节举行领会。
1.让原文文本进取卷动。
if(key.isdown(key.pgdn)) { text1.scroll+=1; } if(key.isdown(key.pgup)){ text1.scroll-=1; }
2.废除shift键码缺点。
shift用来巨细写变换,但他也有本人的键码值。以是咱们必需樊篱掉shift的归来值:
if(key.getcode() !=key.shift ) {//樊篱掉shift的归来值后 var temptext1=text1.charat(selection.getbeginindex()-1); var temptext2=text2.charat(selection.getbeginindex()-1); if(temptext1 !=temptext2 && textlength1!=text2.length) { if(key.getcode() != key.backspace) { errorsound.start(0,1); } textlength1=text2.length; } if(temptext1 ==temptext2 && textlength1!=text2.length) { textlength1=text2.length; if(typesoundplay==true) { typesound.start(0,1); } } } // end of : if(key.getcode() != key.shift)
3.确定何时中断一次熟习,并举行功效统计
if (temptime-nowtimer>=(time*60000)) {//功夫中断 timeover=true;//事变中断标记符 _root.typespace.scores =int( (text2.length*(1+ loopnum))/(time) );//表露功效 speednum=_root.typespace.scores;if(back==false) { //相应熟习中断后没按下back按钮的事变 attachmovie( "showscores","showscores",10+testdepth ); } showscores._x=138;showscores._y=144; for(i=0;i<text2.length;i++)< p> { //show the error num if( text1.charat(i) !=text2.charat(i) ) { errornum++;//统计缺点 } } _root.typespace.error=errornum; stop ();//功夫到就让步调遏止在此 if(back==true)//相应熟习中断后按下back按钮的事变 { removemovieclip("typespace"); removemovieclip("showscores"); gotoandplay(1); back=false; } }// end of if (temptime-nowtimer>=(time*600))
4.让功夫棒精确的表露结余时间长度:
_root.typespace.timebar._width = (1-(temptime- nowtimer)/(60000*time))*timebarwidth;
第6帧,标签“typeend" gotoandplay("typeloop");
4.2.5.4
第4个轮回段第8帧到第10帧.
第8帧 标签“loadnum"
text1="load..."; ranfile=random(4); if(choose=="normaltext") { //导出文本的路途及其称呼 inputtextinputtext= choose add "/" add level add random(4) add ".txt"; } elseinputtext=choose add "/" add random(4) add ".txt";loadvariablesnum(inputtext,0);
第9帧 标签“empty"
第10帧 标签“loadnumend"
if(text1=="load...") { gotoandplay("empty"); trace("gotoand"); } else { loadtext=false; trace("load over"); gotoandplay("mainloop"); }
5.中断语
到此步调领会结束。十足代码所有也惟有100行安排。颁布成的可实行文献巨细也然而30k安排。让人想到了在心爱的dos期间,一张软盘行遍世界的汗青。flash编制程序的特性即是要统筹帧和层的观念,遏制好帧的挪动,就遏制了步调的走向;控制了“层”即是控制了flash动画本领的精华。