as3.0 拖动后看排序是否正确
package com{ import flash.display.MovieClip; import flash.events.MouseEvent; import flash.display.SimpleButton; public class ShunXu { private var thisMc:MovieClip; private var mc:MovieClip; private var arrY:Array=[]; private var startX:Number; private var startY:Number; private var answerArr:Array=["mc4","mc3","mc2","mc1"];//从上到下影片简介的实例名,正确的排列 private var pushName:Array; private var dragMc:MovieClip; private var defineBtn:SimpleButton; private var newMc:MovieClip; public function ShunXu(_thisMc:MovieClip,_mc:MovieClip,_defineBtn:SimpleButton) { mc=_mc; thisMc=_thisMc; defineBtn=_defineBtn; for (var i:uint=0; i<mc.numChildren; i++) { newMc=mc.getChildAt(i) as MovieClip; arrY.push(newMc.y); } defineBtn.addEventListener(MouseEvent.CLICK,onDF); mc.addEventListener(MouseEvent.MOUSE_DOWN,onDown); } private function onDown(e:MouseEvent) { dragMc=e.target as MovieClip; dragMc.startDrag(); mc.setChildIndex(dragMc,mc.numChildren-1); startX=dragMc.x; startY=dragMc.y; thisMc.addEventListener(MouseEvent.MOUSE_UP,onUp); } private function onUp(e:MouseEvent) { dragMc.stopDrag(); thisMc.removeEventListener(MouseEvent.MOUSE_UP,onUp); for (var i=0; i<mc.numChildren; i++) { var newHit:MovieClip=mc.getChildAt(i) as MovieClip; if (dragMc.hitTestObject(newHit)&&dragMc.name!=newHit.name) { dragMc.x=newHit.x; dragMc.y=newHit.y; newHit.x=startX; newHit.y=startY; return; } else { if (i==mc.numChildren-1) { dragMc.x=startX; dragMc.y=startY; } } } } private function onDF(e:MouseEvent) { pushName=[]; for (var j:uint=0; j<answerArr.length; j++) { for (var i=0; i<mc.numChildren; i++) { newMc=mc.getChildAt(i) as MovieClip; if (newMc.y==arrY[j]) { pushName.push(newMc.name); } } } for (i=0; i<mc.numChildren; i++) { if (pushName[i]==answerArr[i]) { if (i==mc.numChildren-1) { trace("正确"); } } else { trace("错误"); return; } } } } }
posted on 2020-03-19 16:11 zqiang0803 阅读(153) 评论(0) 编辑 收藏 举报