I recently completed a tutorial for Ultrashock on creating an MVC based application using forms and screens. Writing it was more of a struggle than I expected, in part due to the lack of documentation on the subject at the time (it has improved since), but also because the current Form implementation lacks a couple of elements that I would consider requisite for developing a clean application:
- The Form class does not include a collection of child forms. This means that you can only reference child forms by a largely arbitrary index number, not by name, unless you declare each child form manually in your class.
- Because the class initializes before the UI components it contains and its child forms, it is very difficult to write logic that sets up and populates interface elements initially, or sets listeners on child forms.
Because these are capabilities I expect I will need for all Form applications, I decided to create a new class that extends the built-in mx.screens.Form class. This way, I can create new classes that extend the GForm class to control my forms, and they will incorporate this new functionality, which currently consists of 2 enhancements:
- Maintains a childForms collection. You can access child forms through this collection by name as such: childForms.formName
- Calls an initUI method of the form immediately after the form finishes loading. This allows you to create an initUI method for your form class that sets up the UI, and any relationships with child forms.
I will likely be updating it with other functionality as I go (assuming I use forms again), and welcome comments on it, so check back for updates.