字词,偏旁组合连线
package com{ import flash.display.MovieClip; import flash.events.MouseEvent; import flash.display.SimpleButton; import flash.utils.Timer; import flash.events.TimerEvent; import flash.geom.ColorTransform; import flash.display.Stage; public class GMwrod4 extends MovieClip { private var startX:Number; private var startY:Number; private var hitMc:MovieClip; private var dragMc:MovieClip; private var eTarMc:MovieClip; private var newDrag:MovieClip; private var hitStr1:String; private var dragStr1:String; private var hitStr2:String; private var dragStr2:String; private var stepNum:Number; private var mcArr:Array; private var newArr:Array; private var XYArr:Array; private var newHitResetArr:Array; private var newDragArr:Array; private var rightArr:Array; private var hitMcArr:Array;//只要碰到hitMc就放到这个里面,如果没有就继续,有就返回原来位置 private var rightNum:Number; private var emptyMc:MovieClip; private var thisMc:MovieClip; private var stageStage:Stage; private var dragRightNum:Number;//要拖对多少个以后才可以连线 public function GMwrod4(_dragMc:MovieClip,_stage:Stage,_dragRightNum:Number) { dragMc=_dragMc; dragMc.buttonMode=true; stageStage=_stage; dragRightNum=_dragRightNum; dragMc.addEventListener(MouseEvent.MOUSE_UP,onClick); dragMc.addEventListener(MouseEvent.MOUSE_DOWN,onClick); newArr=[]; XYArr=[[],[]]; newHitResetArr=[]; newDragArr=[]; rightArr=[]; hitMcArr=[]; stepNum=1; rightNum=1; thisMc=dragMc.parent as MovieClip; emptyMc=new MovieClip(); thisMc.addChild(emptyMc); emptyMc.x=dragMc.x; emptyMc.y=dragMc.y; thisMc.setChildIndex(emptyMc,thisMc.getChildIndex(dragMc)-1); } //================================================================================ private function onClick(e:MouseEvent) { if (e.type=="mouseDown") { eTarMc=e.target as MovieClip; newDrag=eTarMc.parent as MovieClip; startX=newDrag.x; startY=newDrag.y; if (newDragArr.length<dragRightNum&&newDrag.parent.name=="dragMc") { dragMc.setChildIndex(newDrag,dragMc.numChildren-1); newDrag.startDrag(); } else if (newDragArr.length==dragRightNum) { dragMc.addEventListener(MouseEvent.MOUSE_MOVE,onMove); stageStage.addEventListener(MouseEvent.MOUSE_UP,onMove); } } else if (e.type=="mouseUp"&&newDragArr.length<dragRightNum) { stopDrag(); for (var i:uint=dragMc.numChildren-1; i>0; i--) { if (newDrag.name.slice(0,5)=="insta") { newDrag.x=startX; newDrag.y=startY; } else if (newDrag.getChildAt(1).hitTestObject(dragMc.getChildAt(i))&&newDrag.name!=dragMc.getChildAt(i).name) { hitMc=dragMc.getChildAt(i) as MovieClip; hitStr1=hitMc.name.slice(0,5); hitStr2=hitMc.name.slice(-1); dragStr1=newDrag.name.slice(0,5); dragStr2=newDrag.name.slice(-3,-1); if (hitStr1=="hitMc"&&dragStr1=="drag_"&&newDrag.name.indexOf(hitStr2)!=-1) { if (int(newDrag.name.slice(-3,-2))!=0&&hitMcArr.indexOf(hitMc)==-1||newDrag.numChildren==3&&hitMcArr.indexOf(hitMc)==-1) { newDrag.x=hitMc.x; newDrag.y=hitMc.y; XYArr[0].push(startX); XYArr[1].push(startY); newDrag.mouseChildren=false; newDrag.mouseEnabled=false; newDragArr.push(newDrag); hitMcArr.push(hitMc); newHitResetArr.push(newDrag); break; } } else if (hitMc.name.indexOf(dragStr2)!=-1&&hitStr1!=dragStr1&&hitMc.numChildren==2) { hitMc.addChild(newDrag.getChildAt(1)); newDrag.x=startX; newDrag.y=startY; XYArr[0].push(startX); XYArr[1].push(startY); if (hitStr1!="drag_") { hitMc.mouseChildren=false; hitMc.mouseEnabled=false; } newDragArr.push(hitMc); newHitResetArr.push(newDrag); break; } else { newDrag.x=startX; newDrag.y=startY; } } else { if (i==1) { newDrag.x=startX; newDrag.y=startY; } } } } } private function onMove(e:MouseEvent) { if (e.type=="mouseMove") { if (newDragArr.length>=dragRightNum) { //if (e.target.name=="onMove"||e.target.name.slice(0,5)=="hitMc") { //init(); //} for (var d:uint=0; d<newDragArr.length; d++) { newDragArr[d].mouseEnabled=true; newDragArr[d].mouseChildren=true; } eTarMc=e.target as MovieClip; newDrag=eTarMc.parent as MovieClip; var eTarNum:Number=Number(newDrag.getChildAt(0).name.slice(3)); trace(eTarNum,rightNum); if (rightNum==eTarNum&&newDrag.numChildren>=2) { //划线 if (rightNum==1) { DrawLine.DrawLineStart(newDrag.x,newDrag.y); } else { DrawLine.DrawLineStop(newDrag.x,newDrag.y,emptyMc); } MyMusic.changeSound("诗词解谜点击音效"); rightNum++; var mc0:MovieClip=newDrag.getChildAt(0) as MovieClip; var mc1:MovieClip=newDrag.getChildAt(1) as MovieClip; var b:ColorTransform=new ColorTransform(); b.color=0xFFFFFF; mc1.transform.colorTransform=b; mc0.alpha=1; if (newDrag.numChildren==3) { var mc2:MovieClip=newDrag.getChildAt(2) as MovieClip; mc2.transform.colorTransform=b; } } else if (eTarNum-rightNum>0||eTarNum==44||newDrag.numChildren==1||newDrag.numChildren==47) { init(); } } } else { dragMc.removeEventListener(MouseEvent.MOUSE_MOVE,onMove); stageStage.removeEventListener(MouseEvent.MOUSE_UP,onMove); if(rightNum==15){ thisMc.gotoAndStop(thisMc.currentFrame+2) init() } } } private function init() { rightNum=1; dragMc.removeEventListener(MouseEvent.MOUSE_MOVE,onMove); stageStage.removeEventListener(MouseEvent.MOUSE_UP,onMove); for (var h:uint=0; h<dragMc.numChildren; h++) { var backMc:MovieClip=dragMc.getChildAt(h) as MovieClip; if (backMc.numChildren!=1) { //获取dragMc里面的mc var backMc0:MovieClip=backMc.getChildAt(0) as MovieClip; var backMc1:MovieClip=backMc.getChildAt(1) as MovieClip; backMc0.alpha=0; var c:ColorTransform=new ColorTransform(); c.color=0x9F3D1B; backMc1.transform.colorTransform=c; if (backMc.numChildren==3) { var backMc2:MovieClip=backMc.getChildAt(2) as MovieClip; backMc2.transform.colorTransform=c; } } } for (var p:Number=0; p<emptyMc.numChildren; p++) { emptyMc.removeChildAt(p); } } ///撤销功能============================================== public function toolFun(_resetBtn:SimpleButton,_hintBtn:SimpleButton) { _hintBtn.addEventListener(MouseEvent.MOUSE_UP,onHint); _hintBtn.addEventListener(MouseEvent.MOUSE_DOWN,onHint); _resetBtn.addEventListener(MouseEvent.CLICK,onReset); } private function onHint(e:MouseEvent) { if (e.type=="mouseDown") { thisMc.gotoAndStop(thisMc.currentFrame+1); } else { thisMc.gotoAndStop(thisMc.currentFrame-1); } } private function onReset(e:MouseEvent) { var xyArrLength:Number=XYArr[0].length-1; for (var i:uint=0; i<newHitResetArr.length; i++) { if (i==newHitResetArr.length -1) { newDragArr[i].mouseEnabled=true; newDragArr[i].mouseChildren=true; newHitResetArr[i].mouseEnabled=true; newHitResetArr[i].mouseChildren=true; } else { newDragArr[i].mouseEnabled=false; newDragArr[i].mouseChildren=false; newHitResetArr[i].mouseEnabled=false; newHitResetArr[i].mouseChildren=false; } } if (newDragArr[xyArrLength].numChildren==3) { newHitResetArr[xyArrLength].addChild(newDragArr[xyArrLength].getChildAt(2) as MovieClip); } newHitResetArr[xyArrLength].x=XYArr[0][xyArrLength]; newHitResetArr[xyArrLength].y=XYArr[1][xyArrLength]; if (newHitResetArr[xyArrLength].name.slice(0,4)=="drag") { for (var p:uint=0; p<hitMcArr.length; p++) { if (p==hitMcArr.length -1) { hitMcArr[p].mouseEnabled=true; hitMcArr[p].mouseChildren=true; } else { hitMcArr[p].mouseEnabled=false; hitMcArr[p].mouseChildren=false; } } hitMcArr.pop(); } newHitResetArr.pop(); newDragArr.pop(); XYArr[1].pop(); XYArr[0].pop(); } } }
1.拖那都不对的不用写实例名
2.只能组词的b_2
3.能组词还能拖到框里面的drag_1_b_1
4.只能拖框的drag_1_1,为了好计算只好多加了个(_1)
5.可以拖好几个框的drag_2_3_4
6.只能拖进字的底 hitMc_
posted on 2018-12-27 16:42 zqiang0803 阅读(319) 评论(0) 编辑 收藏 举报