PDA

View Full Version : MVC and AMF


strobe33333
06-16-2009, 12:15 AM
Hi,

This is my first post to the forum, but by no means my first use of them. There's a terrific amount of fantastic information in here and I've used it alot, so thanks to those who do the work of hosting and supporting this site.

My question is about the "Best" way to handle AMF in an MVC framework.

1. I'm using AS3 exclusively and building my project with the flex3 compiler (not using the Flash, Flex, or any other IDE or platform.)

2. I'm implementing MVC throughout my application as I intend build several applications off of the same code base.

3. I'm hoping to build an AMF "handler" that I can reuse repeatedly by passing in various information including the name of the onResult function.

My instinct has me treating the NetConnection Object as a Model, so I wrote a class called AMF that takes all the necessary parameters for the netconnection object and subsequent Responder object.

Here's what I don't understand about MVC (and yes I do realize there are more than one flavor of MVC,) would the Responder, event listener, and Netconnection object be split up into different places when utilized in an MVC layout? Or would the model object be self-contained and just return a data object based on what was passed in..

For Example: This is model I wrote to attempt to get re-usability out of an AMF Model Function. But, given what I've read about MVC invocation and separation of duties, I'm totally lost on how to invoke it and get data back


package as3.intranet.data {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.net.NetConnection;
import flash.net.Responder;

//Base amf Model - Assembles and Executes NetConnection
public class AMF {
//Define base vars
//_argument is the object passed into the NetConnection Object to be Parsed
private var _argument:Object;
//_gateway value of amf Gateway URL
private var _gateway:String;
//_pyClass value of the Class to be called on the Gateway
private var _pyClass:String;
//_urlVar value of the url Variable object(s) being passed as argument to Gateway Class
private var _urlVar:String;
//_connection Net Connection Object
private var _connection:NetConnection;
//url URL of the Image
private var url:String;

//NetConnection Function
public function AMF (argument:Object, gateway:String, pyClass:String, urlVar:String) {
trace("Firing AMF Model Function");

_argument = argument;
_gateway = gateway;
_pyClass = pyClass;
_urlVar = urlVar;

//var queryStrings:Object=this.loaderInfo.parameters;
//var picID:int=queryStrings.picID;

//Instantiate NetConnection Object
_connection = new NetConnection();
//_connection.addEventListener(SecurityErrorEvent.SE CURITY_ERROR, onFault);
_connection.connect(gateway);
var responder:Responder = new Responder(onResult, onFault);
_connection.call( pyClass, responder, urlVar );
}

public function onResult(result:Object):void {
trace("Firing Amf onResult Function");
var resultsArray : Array = new Array();
for (var i : * in result){
resultsArray.push(result[i]);
}

trace(resultsArray[1]);
url = resultsArray[2];
trace(url);
return resultsArray;
}

private function onFault (fault:Object) : void{
trace("Firing AMF onFault");
//debugger.text= "Fault" + fault.description;
trace("onFault");
trace(String(fault.description));
}

public function clone():AMF {
return new AMF(_argument, _gateway, _pyClass, _urlVar);
}
}
}


I hope my question is clear enough to respond to without being flamed. I've used the AMF connector object in AS2 alot in the past, but I'm wanting to put some framework and scalability around my works in AS3. I appreciate any suggestions on how this would best be implemented.

Thank You,

Joel
www.j03l.com

P.S. This is where I got my MVC know-how from if it helps

http://books.google.com/books?id=DT7INNE3ui8C&printsec=frontcover&dq=Advanced+Actionscript+3&ei=Meg2Sq6EHJTSkASK5OTRDA#PPA48,M1