3 Replies Latest reply on Feb 18, 2010 11:35 PM by archemedia

    New to Flex basic question....

    invaliduser

      Hello everyone,

       

      I am a Java developer new to Flex and was wondering if someone can answer a simple question for me. I have read a few Flex books now and I am tasked with developing new functionality into my companies current Flex infrastructure. None of these books have really addressed this issue enough.

       

      The basic questions is about best practices with a Flex app. Digging through the code I have noticed a lot of event handling and business logic in script tags in MXML files. Some MXML files are as large as 3500 lines long! Most of the code is between script tags and appears to be event handlers and such, but there are also calls to a custom query object. Also I must say that we are not using any framework as they have developed their own which actually wraps Flex.

       

      Coming from a Java background I have been trained to use best practices of seperating business logic out into service classes and having controller call the service layer to get things done.

       

      Can someone please enlighten me as to the placement of event handlers and business logic within a Flex application? Is it standard to have big scripting areas within each MXML file that contains all the event handlers and such?

       

      Thanks!

        • 1. Re: New to Flex basic question....
          saisri2k2 Level 4

          Ya, Even i do the same.. One component sooo much code in it..why do we do that???   coz.... it is difficult to get handle/reference to the sub components in some other files (like link buttton, textinput, button etc., so, people prefer to write all the logic in the same page.. and comming to events .. you can track down whoz interested in that event by double clicking on event class name (eg: CustomClass.EVENT_NAME) DOUBLE CLICK ON customclass and  Reference > project to search for the listeners..

          • 2. Re: New to Flex basic question....
            John Hall Level 4

            As you might guess, it's so difficult to answer your concerns because it depends on what you're doing. In general, though, Flex developers try to separate the logic from the view so that it would be less than best practice, imho, to put a lot of code in the views. I've become a fan of the presentation model as used in Mate (I know, you folks have your own framework) but still, I think it's preferable to solely bind attributes in views and keep all the logic in managers or presentation managers that model the state of the view. So, bottom line, IMHO mxml files the size of what you're talking about are unusual and crazy difficult to figure out.

            • 3. Re: New to Flex basic question....
              archemedia Level 4

              There are a few good starting points:

               

              1. Study the singleton design pattern. This enables you to work with single class instances which are great for model and controller objects. They can handle all logic, completely separated from your views.

               

              2. Work with custom components (through actionScript or mxml)

               

              3. Although I'm not a huge fan of it, it's worth reading on Cairngorm, which implements pure mvc.

              http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm

               

              Dany