五子棋效果

package {
	import flash.display.MorphShape;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.text.TextField;

	/*
	      *author : SinSoul 
	      *blogs: http://www.cnblogs.com/sinsoul
	 
	*/
	public class Main extends MovieClip {//定义了一个Main的类 他继承了MovieClip影片剪辑;
		var txt:TextField=new TextField  ;
		var bur:Boolean=false;
		var arr:Array=new Array();
		public function Main() {//要有主构造 函数
			//声明实例添加到舞台,并且添加点击事件
			for (var i:int=0; i<10; i++) {

				for (var ii:int=0; ii<10; ii++) {
					var mc:MC=new MC  ;
					arr.push(mc);
					addChild(mc);
					mc.stop();
					mc.x=ii*mc.width;

					mc.y=i*mc.height;
					//function dians


				}
			}
			for (var a:int=0; a<100; a++) {
				arr[a].addEventListener(MouseEvent.CLICK,dian);
				arr[a].buttonMode=true;


			}


		}
		public function dian(e:MouseEvent):void {
			var mc:MovieClip=e.currentTarget as MovieClip;//e.currentTarget鼠标的当前点击目标对象把它(as)作为 成影片剪辑
			if (bur==false) {
				//trace(2);
				mc.gotoAndStop(2);
				bur=true;

			} else {
				mc.gotoAndStop(3);
				bur=false;
				//trace(3);
			}
			mc.removeEventListener(MouseEvent.CLICK,dian);

			txt.text=String(arr.indexOf(mc));
			addChild(txt);
			txt.x=stage.stageWidth-txt.textWidth;


		}


	}


}

posted @ 2010-11-13 15:29  sinsoul  阅读(265)  评论(0编辑  收藏  举报