码迷,mamicode.com
首页 > 移动开发 > 详细

移动框选择答案

时间:2019-03-14 16:42:01      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:end   .text   get   parent   private   top   ram   int   frame   

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 = [];
            }
        }
    }

}

 

移动框选择答案

标签:end   .text   get   parent   private   top   ram   int   frame   

原文地址:https://www.cnblogs.com/zqiang0803/p/10530926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!