拖动字到框,点击框字返回

package com{
    import flash.display.MovieClip;
    import flash.display.SimpleButton;
    import flash.events.MouseEvent;
    import flash.text.TextField;

    public class FristFrame extends MovieClip {

        private var txtMc:MovieClip;
        private var thisMc:MovieClip;
        private var dragMc:MovieClip;
        private var txtArr:Array=[];
        private var wordArr:Array=[];
        public static var answerArr:Array=[[],[],[],[]];
        private var newDrag:MovieClip;
        private var txtStr:String;
        private var str:String;

        private var startX:Number;
        private var startY:Number;

        private var nextBtn:SimpleButton;
        public function FristFrame(_thisMc:MovieClip,_dragMc:MovieClip,_txtMc:MovieClip) {
            txtMc=_txtMc;
            thisMc=_thisMc;
            dragMc=_dragMc;

            for (var i:uint=0; i<txtMc.numChildren; i++) {
                var newTxtMc:MovieClip=txtMc.getChildAt(i) as MovieClip;
                for (var j:uint=0; j<newTxtMc.numChildren; j++) {
                    var txt:TextField=newTxtMc.getChildAt(j) as TextField;
                    //txt.text="";
                }
            }
            txtMc.addEventListener(MouseEvent.MOUSE_DOWN,onTxtMc)
            dragMc.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
        }
        private function onTxtMc(e:MouseEvent){
            var _txt:TextField=e.target as TextField
            if(_txt.text!=""){
                var str:String=_txt.text
                dragMc[str].visible=true
                _txt.text=""
            }
        }
        private function onDown(e:MouseEvent) {
            str=e.target.parent.name;
            if (str=="dragMc") {
                thisMc.stage.addEventListener(MouseEvent.MOUSE_UP,onUp);
                newDrag=e.target as MovieClip;
                startX=newDrag.x;
                startY=newDrag.y;
                newDrag.startDrag();

                for (var i:uint=0; i<dragMc.numChildren; i++) {
                    if (newDrag.name==dragMc.getChildAt(i).name) {
                        txtStr=e.target.name;
                    }
                }
            }

        }
        private function onUp(e:MouseEvent) {
            stopDrag();
            
            for (var i:uint=0; i<txtMc.numChildren; i++) {
                var newTxtMc:MovieClip=txtMc.getChildAt(i) as MovieClip;
                for (var j:uint=0; j<newTxtMc.numChildren; j++) {
                    var txt:TextField=newTxtMc.getChildAt(j) as TextField;
                    if (newDrag.hitTestObject(txt)) {
                        txt.text=txtStr;
                        newDrag.visible=false
                        break;
                    }
                }
            }
            newDrag.x=startX;
            newDrag.y=startY;

            thisMc.stage.removeEventListener(MouseEvent.MOUSE_UP,onUp);
        }
        public function nextFun(_nextBtn:SimpleButton) {
            nextBtn=_nextBtn;
            nextBtn.addEventListener(MouseEvent.CLICK,onNextBtn);
        }
        private function onNextBtn(e:MouseEvent) {
            var txtStr:String=""
            for (var i:uint=0; i<txtMc.numChildren; i++) {
                var newTxtMc:MovieClip=txtMc.getChildAt(i) as MovieClip;
                for (var j:uint=0; j<newTxtMc.numChildren; j++) {
                    var txt:TextField=newTxtMc.getChildAt(j) as TextField;
                    txtStr+=txt.text
                    if (j==newTxtMc.numChildren-1) {
                        answerArr[i].push(txtStr);
                        txtStr=""
                    }
                }
            }
            nextBtn.removeEventListener(MouseEvent.CLICK,onNextBtn);
            thisMc.nextFrame();
            trace(answerArr.length );
            trace(answerArr );
        }
//答案
        private var arr1:Array=["123","123","123","123"];
        public function Answer1(_mc:MovieClip ) {

            for (var i:uint=0; i<arr1.length; i++) {
                //_mc["answerMc"].getChildAt(i).alpha=0;
                _mc["answerMc"].alpha=0;
                var txt:TextField=_mc["txtMc"].getChildAt(i) as TextField;
                txt.text=FristFrame.answerArr[i];
                if (arr1.indexOf(txt.text)!=-1) {
                    funnum0();
                } else {
                    //var newRight:MovieClip=_mc["rightMc"].getChildAt(i) as MovieClip;
                    //newRight.nextFrame();
                    //_mc["answerMc"].getChildAt(i).alpha=1;
                    _mc["right"].nextFrame();
                    _mc["answerMc"].alpha=1;
                }
            }
        }

 


    }

}

 

posted on 2019-05-08 14:25  zqiang0803  阅读(145)  评论(0编辑  收藏  举报

导航