码迷,mamicode.com
首页 > 其他好文 > 详细

连一连

时间:2018-06-16 18:40:22      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:ddc   geo   global   icm   mouse   one   xtend   rap   extends   

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;

    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 downName:String=null;
        private var point:Point;
        private var newPoint:Point;
        private var eTarMc:MovieClip;
        private var mcArr:Array=[];
        private var McArr:Array=[];
        private var musicArr:Array=["","恭喜你,都连对了","","正确"];
        private var mm:MyMusic=new MyMusic  ;
        public function Line(_wordMc:MovieClip,_picMc:MovieClip,_emptyMc:MovieClip,_color:uint=0xFF0000,_size:uint=5) {
            wordMc=_wordMc;
            picMc=_picMc;
            emptyMc=_emptyMc;
            color=_color;
            size=_size;
            clearDeaw();
            MyMusic.initialSound(musicArr[0]);
            wordMc.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
            picMc.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
        }

        private function onDown(e:MouseEvent) {
            eTarMc=e.target as MovieClip;
            point=new Point(e.target.x,e.target.y);
            newPoint=e.currentTarget.localToGlobal(point);
            if (eTarMc.alpha==0) {
                eTarMc.alpha=1;
                mcArr.push(e.target);
                McArr.push(e.currentTarget);


                if ((downName==null)) {
                    downName=e.target.name.slice(0,2);
                    line=new Shape  ;
                    emptyMc.addChild(line);
                    line.graphics.lineStyle(size,color);
                    if (e.target.name.slice(0,2)=="wo") {
                        line.graphics.moveTo(newPoint.x+e.target.width/2,newPoint.y+e.target.height);
                    } else if (e.target.name.slice(0,2)=="pi") {
                        line.graphics.moveTo(newPoint.x+e.target.width/2,newPoint.y);
                    }
                } else if ((downName!=e.target.name.slice(0,2))) {
                    if (e.target.name.slice(0,2)=="wo") {
                        line.graphics.lineTo(newPoint.x+e.target.width/2,newPoint.y+e.target.height);
                    } else if (e.target.name.slice(0,2)=="pi") {
                        line.graphics.lineTo(newPoint.x+e.target.width/2,newPoint.y);
                    }
                    if (mcArr[0].name.slice(-1)==mcArr[1].name.slice(-1)||McArr[0].name==McArr[1].name) {
                        if (emptyMc.numChildren==5) {
                            MyMusic.initialSound(musicArr[1]);
                            explainMc.gotoAndStop(3);
                        }
                        MyMusic.initialSound(musicArr[3]);
                    } else {
                        line.graphics.clear();
                        emptyMc.removeChild(line);
                        McArr[0][mcArr[0].name].alpha=0;
                        McArr[1][mcArr[1].name].alpha=0;
                        MyMusic.initialSound(musicArr[2]);
                    }

                    mcArr=[];
                    McArr=[];
                    downName=null;
                } else {
                    line.graphics.clear();
                    emptyMc.removeChild(line);
                    McArr[1][mcArr[1].name].alpha=0;
                    McArr[0][mcArr[0].name].alpha=0;
                    mcArr=[];
                    McArr=[];
                    downName=null;

                }
            }
        }

        //弹框
        private var explainMc:MovieClip;
        public function explainFun(_explainMc:MovieClip) {
            explainMc=_explainMc;
            explainMc.gotoAndStop(2);
            explainMc.addEventListener(MouseEvent.CLICK,onExplain);
        }
        private function onExplain(e:MouseEvent) {
            if (e.target.name=="startGameBtn") {
                explainMc.gotoAndStop(1);
                MyMusic.pauseFuntion();
            } else if (e.target .name=="againBtn") {
                explainMc.gotoAndStop(1);
                MyMusic.pauseFuntion();
                clearDeaw();
            }
        }

        public function clearDeaw() {
            while (emptyMc.numChildren>0) {
                emptyMc.removeChildAt(0);
            }
            mcArr=[];
            McArr=[];
            downName=null;
            for (var i:uint=0; i<picMc.numChildren; i++) {
                picMc.getChildAt(i).alpha=0;
                wordMc.getChildAt(i).alpha=0;
            }
        }

    }
}

 

连一连

标签:ddc   geo   global   icm   mouse   one   xtend   rap   extends   

原文地址:https://www.cnblogs.com/zqiang0803/p/9190903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!