移动框选择答案

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 ThirdFrame extends MovieClip {

        private var moveMc:MovieClip;
        private var thisMc:MovieClip;
        private var arr:Array=["A","B","C","D","E","F"];
        private var getChildAtNum:Number;
        public static var answerArr:Array=[];
        private var stageMc:Stage;
        public function ThirdFrame(_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 movieMc:MovieClip;
        private var txtMc:MovieClip;
        public function clickFun(_moveMc:MovieClip,_txtMc:MovieClip ) {
            txtMc=_txtMc;
            moveMc=_moveMc;
            moveMc.visible=false;
            txtMc.addEventListener(MouseEvent.CLICK,onTxt);
            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 onTxt(e:MouseEvent) {

            var point:Point=new Point(e.target.x,e.target.y);
            point=txtMc.localToGlobal(point);
            moveMc.x=point.x;
            moveMc.y=point.y+txtMc.height
            moveMc.visible=true;

            for (var i:uint =0; i<txtMc.numChildren; i++) {
                if (txtMc.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;
                answerArr.push(newTxt.text);
            }
            txtMc.removeEventListener(MouseEvent.CLICK,onTxt);
            moveMc.removeEventListener(MouseEvent.CLICK,moveFun);
          //  stageMc.removeEventListener(MouseEvent.CLICK,stageFun);
            nextBtn.removeEventListener(MouseEvent.CLICK,onNextBtn);
            trace(answerArr)
            thisMc.nextFrame();
        }
    }

}

 

posted on 2019-03-14 16:06  zqiang0803  阅读(152)  评论(0编辑  收藏  举报

导航