1 Reply Latest reply on Jun 6, 2008 7:16 AM by matthew horn

    Converting MXML Components to ActionScript Classes

    ericbelair Level 1
      I'm in the process of converting most (if not all) of my MXML components to Action Script classes. I've found this is easy, and doesn't require a lot of extra code when extending a simple container or control. However, several of my MXML components have several nested containers and controls - i.e. a component that contains several Labels, a ComboBox, a TextInput, a Button, and a DataGrid, plus several other containers needed for layout. To code the layout of all these containers and controls using MXML, it uses about 16 lines of code. To code the layout in ActionScript, it takes about 50+ lines of code (see attached).

      I'm just wondering if there are any best practices for creating ActionScript classes that include several (or even A LOT OF) containers and controls. It's very easy to layout in MXML, and is more visibly pleasing to look at and understand, but I feel it is best practice to code components as ActionScript classes. I know I should be using MVC, but it's a little late to rewrite the entire application now.

      Any thoughts?
        • 1. Re: Converting MXML Components to ActionScript Classes
          matthew horn Level 3
          I can't specifically speak to how to write layout code in ActionScript, but you can look at the generated code that Flex creates to get an idea of how Flex does it. When you compile an app, the Flex compiler takes your MXML input and converts it to ActionScript classes before compiling the entire set of classes into a SWF. Because of this, you can look at the interim ActionScript code.

          You do this by setting the keep-generated-actionscript compiler option to true and looking in the /generated directory.

          hth,

          matt horn
          flex docs