连线
package com{ import flash.display.MovieClip; import flash.display.Shape; import flash.events.MouseEvent; import fl.motion.Color; import flash.events.Event; import flash.geom.Point; import flash.display.SimpleButton; import flash.utils.Timer; import flash.events.TimerEvent; public class Line extends MovieClip { private var picMc:MovieClip; private var wordMc:MovieClip; private var emptyMc:MovieClip; private var color:uint; private var size:uint; private var line:Shape; private var point:Point; private var newPoint:Point; private var eTar:Object; private var eTarArr:Array = []; private var rightNum:Number; private var thisMc:MovieClip; public function Line(_wordMc:MovieClip,_picMc:MovieClip,_emptyMc:MovieClip,_color:uint=0,_size:uint=1) { wordMc = _wordMc; picMc = _picMc; emptyMc = _emptyMc; color = _color; size = _size; thisMc = picMc.parent as MovieClip; picMc.buttonMode = true; wordMc.buttonMode = true; rightNum = picMc.numChildren; if (wordMc.hasEventListener(MouseEvent.MOUSE_DOWN) == false) { wordMc.addEventListener(MouseEvent.MOUSE_DOWN,onDown); picMc.addEventListener(MouseEvent.MOUSE_DOWN,onDown); } eTarArr = []; for (var i:uint = 0; i < wordMc.numChildren; i++) { wordMc.getChildAt(i).alpha = 0; picMc.getChildAt(i).alpha = 0; } while (emptyMc.numChildren > 0) { emptyMc.removeChildAt(0); } } private function onDown(e:MouseEvent) { eTar = e.target as Object; point = new Point(e.target.x,e.target.y); var eTarParen:MovieClip = e.target.parent as MovieClip; newPoint = eTarParen.localToGlobal(point); if (eTar.alpha == 0) { eTar.alpha = 1; if (eTarArr.length == 0) { line = new Shape ; line.graphics.lineStyle(size,color); line.graphics.moveTo(newPoint.x,newPoint.y); } eTarArr.push(eTar); if (eTarArr.length > 1) { if (eTarArr[0].parent.name != eTarArr[1].parent.name) { if (eTarArr[0].name.slice(-1) == eTarArr[1].name.slice(-1)) { line.graphics.lineTo(newPoint.x,newPoint.y); emptyMc.addChild(line); MyMusic.changeSound("正确"); } else { eTarArr[0].alpha = 0; eTarArr[1].alpha = 0; } if (emptyMc.numChildren == rightNum) { var thisMc:MovieClip = emptyMc.parent as MovieClip; var t:Timer = new Timer(800,1); t.addEventListener(TimerEvent.TIMER,onT); t.start(); function onT(e:TimerEvent) { MyMusic.changeSound("连一连2"); explainMc.gotoAndStop(3); } } eTarArr = []; } else { eTarArr[0].alpha = 0; eTarArr.shift(); line.graphics.moveTo(newPoint.x,newPoint.y); } } } } private var explainMc:MovieClip; public function explainFun(_explainMc:MovieClip) { explainMc = _explainMc; if (explainMc.hasEventListener(MouseEvent.CLICK) == false) { explainMc.addEventListener(MouseEvent.CLICK,onExp); MyMusic.changeSound("连一连1"); } } private function onExp(e:MouseEvent) { var str:String = e.target.name; if (str == "startGameBtn"){ explainMc.gotoAndStop(1); MyMusic.pauseFuntion(); } else if ((str == "againBtn")) { MyMusic.pauseFuntion(); eTarArr = []; explainMc.gotoAndStop(1); while (emptyMc.numChildren > 0) { emptyMc.removeChildAt(0); } for (var i:uint = 0; i < wordMc.numChildren; i++) { thisMc["wordMc"].getChildAt(i).alpha = 0; thisMc["picMc"].getChildAt(i).alpha = 0; } } } } }
posted on 2019-04-01 16:07 zqiang0803 阅读(141) 评论(0) 编辑 收藏 举报