I am trying to figure out the MVC patter in flash builder. I understand we can seperate view and controller by building custom components as view and populate them in the controller file. However, I don't know how to apply the Model login in flash builder. Do i create a Model folder and file and using that file to receive data?
<?xml version="1.0" encoding="utf-8"?>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:HTTPService url="test.come" id="testData" result="testData_resultHandler(event)"/> //Data here
public var testData:ArrayCollection;
protected function testData_resultHandler(event:ResultEvent):void
testData=event.result.something... //How to seperate the Data with the main controller?????
I appreciate any replies. Thanks a lot.
The usual pattern in flex is to have an mxml component 'the view', an actionscript class (the controller), and some additional actionscript classes that represent the data objects (the model). Your 'main' application class is responsible for creating a new instance of the controller, usually as response to the creationComplete event. The controller then initiallizes/retrieves the 'Model' objects and passes them back to the view which binds them to the appropriate fields. So at the bare minimum for an MVC project your are going to have Main.mxml, MainController.as, and Model.as.
This is not the most elegant solution since it tends to create tight coupling between the controller and the view. If you want to use the MVC pattern on any project that involves more than 3 or 4 simple views you will probably want to look into a custom MVC framework like Cairingorm or the Tide framework from GraniteDS. Make sure you have a solid understanding of the basics first though.