MVC模式

1.modle

package
{
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class modle extends EventDispatcher
	{
		private var mint;
		private var mheight:int;
		public function modle()
		{
			
		}
		public function get Mwidth():int
		{
			return mwidth;
		}
		public function set Mwidth(value:int):void
		{
			mwidth = value;
		}
		
		public function get Mheight():int
		{
			return mheight;
		}
		public function set Mheight(value:int):void
		{
			mheight = value;
		}
		
		public function ChangeModel(_int,_height:int):void
		{
			Mwidth = _width;
			Mheight = _height;
			dispatchEvent(new Event("change"));
		}
	}
}

2.view 

package
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;

	public class view extends Sprite
	{
		private var theModle:modle;
		private var theController:controller;
		private var shape:Shape
		public function view(_model:modle, _controller:controller)
		{
			shape = new Shape();
			shape.graphics.beginFill(0xffff00);
			shape.graphics.drawRect(0,0,100,100);
			shape.graphics.endFill();
			addChild(shape);
			theModle = _model;
			theController = _controller;
			theModle.addEventListener("change", HandleDraw);
		}
		private function HandleDraw(evt:Event):void
		{
			shape.width = theModle.Mwidth;
			shape.height = theModle.Mheight;
		}
		//添加按钮,调用这个方法刷新Model
		public function RefreshModel():void
		{
			theController.changeModle();
		}
	}
}

3.controller

package
{
	public class controller
	{
		private var theModle:modle
		public function controller(_modle:modle)
		{
			theModle = _modle;
		}
		public function changeModle():void
		{
			theModle.ChangeModel(200,200);
		}
	}
}

4.运行

var mo:modle = new modle();
var col:controller = new controller(mo);
var vi:view = new view(mo,col);
addChild(vi);
vi.RefreshModel();
原文地址:https://www.cnblogs.com/mzbdadou/p/2101302.html