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

Posted zqiang0803

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了拖动字到框,点击框字返回相关的知识,希望对你有一定的参考价值。

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;
                }
            }
        }

 


    }

}

 

以上是关于拖动字到框,点击框字返回的主要内容,如果未能解决你的问题,请参考以下文章

JavaFX窗口拖动

点击“产品详细信息”页面上的“添加到框”按钮后,网站会放大

如何在html添加一个搜索框和一个按钮?点击按钮,就搜索到框里的内容

在使用 Hive 进行颤振时,您如何将自定义对象从 POST 响应正文添加到框?

为啥 Excel 2010 VBA 用户窗体文本框字体会根据框架的大小而变化?

使用导航架构操作点击返回按钮时如何避免片段重新创建?