as3.0 点字出现字
//帧上 import com.FifthFrame; FifthFrame.answerStr="2222222" FifthFrame.wordStr="22222222222222222" var f5:FifthFrame=new FifthFrame(this,clickMc,txtMc) f5.nextFun(nextBtn)
package com{ import flash.display.MovieClip; import flash.events.MouseEvent; import flash.text.TextField; import flash.display.SimpleButton; public class FifthFrame extends MovieClip { private var thisMc:MovieClip; private var clickMc:MovieClip; private var txtMc:MovieClip; private var stepNum:Number; private var roundInt:int; private var roundArr:Array; public static var answerStr:String; private var removeArr:Array; public static var wordStr:String; public static var answerArr=[]; public function FifthFrame(_thisMc:MovieClip,_clickMc:MovieClip,_txtMc:MovieClip) { thisMc=_thisMc; clickMc=_clickMc; txtMc=_txtMc; txtMc.addEventListener(MouseEvent.CLICK,onTxt); clickMc.addEventListener(MouseEvent.CLICK,onClick); init(); } private function rightInit() { //txtMc 变空 removeArr=[]; answerStr=""; for (var i:uint=0; i<txtMc.numChildren; i++) { var txt:TextField=txtMc.getChildAt(i) as TextField; txt.text=""; } } private function init() { roundArr=[]; stepNum=0; answerStr=""; rightInit(); //选择空数字 while (roundArr.length<clickMc.numChildren) { roundInt=Math.random()*clickMc.numChildren; if (roundArr.indexOf(roundInt)==-1) { roundArr.push(roundInt); } } //内容填进点击的 for (var j:uint=0; j<clickMc.numChildren; j++) { var _txt:TextField=clickMc.getChildAt(j) as TextField; _txt.text=wordStr.slice(roundArr[j],roundArr[j]+1); } } private function onClick(e:MouseEvent) { var eTarTxt:TextField=e.target as TextField; if (stepNum<txtMc.numChildren) { removeArr.push(eTarTxt); clickMc.removeChild(eTarTxt); stepNum++; for (var i:uint=0; i<txtMc.numChildren; i++) { var txt:TextField=txtMc.getChildAt(i) as TextField; if (txt.text=="") { txt.text=eTarTxt.text; break; } } } } private function onTxt(e:MouseEvent) { var eTarTxt:TextField=e.target as TextField; for (var i:Number=0; i<removeArr.length; i++) { var txt:TextField=removeArr[i] as TextField; if (txt.text==eTarTxt.text) { stepNum--; clickMc.addChild(txt); var n:Number=removeArr.indexOf(txt); removeArr.splice(n,1); eTarTxt.text=""; break; } } } private var nextBtn:SimpleButton; public function nextFun(_nextBtn:SimpleButton ) { nextBtn=_nextBtn; nextBtn.addEventListener(MouseEvent.CLICK,onNextBtn); } private function onNextBtn(e:MouseEvent) { for (var j:uint=0; j<txtMc.numChildren; j++) { answerStr+=TextField(txtMc.getChildAt(j)).text; if (j==txtMc.numChildren-1) { trace(answerStr); } } thisMc.nextFrame() nextBtn.removeEventListener(MouseEvent.CLICK,onNextBtn); } } }
//答案 private var arr5:Array=["12312312323"]; public function Answer5(_mc:MovieClip ) { var str:String=""; _mc["anwerMc"].visible=false; for (var i:uint=0; i<_mc["txtMc"].numChildren; i++) { var newTxt:TextField=_mc["txtMc"].getChildAt(i) as TextField; newTxt.text=""; } for (var j:uint=0; j<FifthFrame.answerStr.length; j++) { var newTxt1:TextField=_mc["txtMc"].getChildAt(j) as TextField; newTxt1.text=FifthFrame.answerStr.slice(j,(j+1)); str+=newTxt1.text; } if (str==arr5[0]) { funnum4(); } else { trace("错误"); _mc["right"].nextFrame(); _mc["anwerMc"].visible=true; } }
posted on 2019-05-30 15:23 zqiang0803 阅读(260) 评论(0) 编辑 收藏 举报