移动框选择答案
Posted zqiang0803
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了移动框选择答案相关的知识,希望对你有一定的参考价值。
package com{ import flash.display.MovieClip; import flash.events.MouseEvent; import flash.display.SimpleButton; import flash.display.Stage; import flash.geom.Point; import flash.text.TextField; public class SecondFrame extends MovieClip { private var moveMc:MovieClip; private var thisMc:MovieClip; private var arr:Array = ["A","B","C","D"]; private var getChildAtNum:Number; public static var answerArr:Array = []; private var stageMc:Stage; public function SecondFrame(_thisMc:MovieClip,_stageMc:Stage ) { thisMc = _thisMc; stageMc = _stageMc; stageMc.addEventListener(MouseEvent.CLICK,stageFun); } private function stageFun(e:MouseEvent) { moveMc.visible = false; e.stopImmediatePropagation(); } private var btnMc:MovieClip; private var movieMc:MovieClip; private var txtMc:MovieClip; public function clickFun(_btnMc:MovieClip ,_moveMc:MovieClip,_txtMc:MovieClip ) { btnMc = _btnMc; txtMc = _txtMc; moveMc = _moveMc; moveMc.visible = false; btnMc.addEventListener(MouseEvent.CLICK,onBtnMc); moveMc.addEventListener(MouseEvent.CLICK,moveFun); for (var i:uint =0; i<txtMc.numChildren; i++) { var newTxt:TextField = txtMc.getChildAt(i) as TextField; newTxt.text = ""; } } private function onBtnMc(e:MouseEvent) { var point:Point = new Point(e.target.x,e.target.y); point = btnMc.localToGlobal(point); moveMc.x = point.x; moveMc.y = point.y + 5; moveMc.visible = true; for (var i:uint =0; i<btnMc.numChildren; i++) { if (btnMc.getChildAt(i).name == e.target.name) { getChildAtNum = i; break; } } e.stopPropagation(); } private function moveFun(e:MouseEvent) { if (e.target.parent.name == "choiceMc") { var newChoiceMc:MovieClip = e.target.parent as MovieClip; for (var i:uint=0; i<newChoiceMc.numChildren; i++) { if (e.target.name == newChoiceMc.getChildAt(i).name) { var txt1:TextField = txtMc.getChildAt(getChildAtNum) as TextField; txt1.text = arr[i]; } } e.stopPropagation(); } } private var nextBtn:SimpleButton; public function nextFun(_nextBtn:SimpleButton ) { nextBtn = _nextBtn; nextBtn.addEventListener(MouseEvent.CLICK,onNextBtn); } private function onNextBtn(e:MouseEvent) { for (var i:uint =0; i<txtMc.numChildren; i++) { var newTxt:TextField = txtMc.getChildAt(i) as TextField; if (newTxt.text != "") { answerArr.push(newTxt.text); } } if (answerArr.length == btnMc.numChildren) { thisMc.nextFrame(); stageMc.removeEventListener(MouseEvent.CLICK,stageFun); nextBtn.removeEventListener(MouseEvent.CLICK,onNextBtn); } else { answerArr = []; } } } }
以上是关于移动框选择答案的主要内容,如果未能解决你的问题,请参考以下文章