Controller class

package flashscriptMVC
{
	import flashscriptMVC.IModel;
	import flashscriptMVC.IControlHandler;
	import flashscriptMVC.events.TextHandlerEvent;
	import biz.flashscript.utils.LoadData;
	import flash.net.URLVariables;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	public class Controller extends AbstractClass implements IControlHandler
	{
		private var m:IModel;
		
		public function Controller  (aModel:IModel, aController:IControlHandler = null)
		{
			super (aModel,aController);
			m = aModel as IModel;
			/*
			* Here we define the Eventlisteners for events dispatched from
			* the views.
			*/
			addEventListener("textHandler",submitChangeHandler);
			addEventListener("serverResponse",serverResponseHandler);
		}
/*
* The controller class contains a number of functions and communicates with the 
* Viewers and the Model class. 
*/
		public function alertChangeHandler (aText:String, yesNo:Boolean, aTarget:Object):void
		{
			m.alertText = aText;
			m.alertYesno = yesNo;
			m.alertTarget = aTarget;
			m.alert ();
		}
	}
/*
* Function to send data to the server. This function is triggered by
* the viewer by for example using the submit button. The for.. loop
* catches arrays for the variable names and for the variable values
* which come from textfields or comboboxes etc. The variable identifiers
* can be set in the XML file.
*/
		private function submitChangeHandler (event:TextHandlerEvent):void
		{
			var datArray:Array = event.dataAr;
			var varArray:Array = event.varAr;
			var dataFile:String = event.myURL;
			
			var myURLVariables:URLVariables = new URLVariables();
			for (var count:int = 0; count < datArray.length; count++)
			{
				myURLVariables[varArray[count]] = datArray[count];
			}
			var myLoader:LoadData = new LoadData();
			myLoader.initLoader (dataFile,completeHandler,null,myURLVariables);
		}
/*
* Serverresponse. In this function all what is done is sent a response
* back to the viewer depending on what comes frome the server, an 'Okay" 
* or an "Error" message.
*/
		private function completeHandler (event:Event, a:Object, b:Object, c:Object):void
		{
			if (event.currentTarget.data.myResult == "Okay")
			{
				m.okayHandler();
			}
			else
			{
				m.errorHandler();
			}
		}
/*
* Function as a response to the server to open a new URL.
*/
		private function serverResponseHandler (event:TextHandlerEvent):void
		{
			var url:String = event.myURL;
			var request:URLRequest = new URLRequest(url);
			navigateToURL (request,"_self");
		}
	}
}