Flex best practices – Part 1: Setting up your Flex project
Use a common directory for your Flex workspace in team environments.
A Flex workspace is unique to each computer on which Flex Builder has been installed. Therefore, each developer can have her own workspace defined. To keep things clear for a team of developers, it is probably a good idea to agree on one workspace, or at least agree on a top-level directory in which to store the multiple workspaces. An example is:
The reason this can be helpful is that everyone will immediately know where to look to find your Flex workspaces or projects, depending on the granularity that you have chosen for your development process. This is a simple thing to do that saves me from having to refer to the Flex Builder workspace settings to figure out where a particular developer stores her files.
Naming conventions for Flex projects
Follow the best practices below on naming conventions for your Flex projects:
Follow common naming conventions for Flex project names.
For Flex project names, you should always begin with a capital letter, and each subsequent word should also be capitalized. This is called "UpperCamelCase". An example name would be "MyGreatFlexApplication". This is also the name that Flex Builder will use for the application's main deployable MXML file. Note: the Flex project name can be changed at any later point in time.
Determining the application type
Follow the best practices below on determining the application type:
Determine your target platform.
Flex applications can target the Flash Player, which will run in a web browser or the Adobe Integrated Runtime (AIR). When you create Flex projects, you will be prompted to set the application type. This can enable you to set up the project to target the web browser or AIR and minimize the amount of potential re-work that could be required later if you decide to add or change the target platform.
If you do wish to target both the desktop (AIR) and the web browser, additional information can be found in Todd Prekaski's article Building Flex and Adobe AIR applications from the same code base.
Setting the Flex project output
Follow the best practices below on setting the Flex project output:
Stick with the default "bin-debug" directory unless your Flex project uses a local development server.
When Flex projects are compiled, the files that comprise the application are created and written to the Flex project's output directory, called "bin-debug". If you are new to Flex, I recommend using the default "bin-debug" directory to eliminate confusion. However, this is another area where you should check with your organization's standards. If your team is using another output directory, you should follow the preexisting best practices.
If your Flex project uses a local development server, you will need to define the path during the project creation process.
When you are ready to deploy your application using "Export Release Build...", Flex Builder 3.0 will create a new output directory. The default name will be "bin-release".
In review, the output directory will be:
- For development: "bin-debug"
- For deployment: "bin-release"
Managing the source code directory
Follow the best practices below on managing the source code directory:
Always place source code in a directory named "src".
This is a far-reaching standard that is shared by developers of different backgrounds and languages. Most developers will know to look here for your code. This is the default value provided by Flex Builder 3.0, and I recommend you leave it.
Use object-oriented programming practices for Flex projects.
You will see more detailed standards for working with packages later in this article. For now, keep in mind that following OOP practices is fundamental to Flex application development.
Considering source control management
Follow the best practices below on considering source control management:
Use a source code control solution for your "Main source" folder.
Source control management (SCM) is critical in team environments. Source control will enable your team to track changes being made to your application's codebase. Source control gives your team the ability to step forward and backward through a file's history. It is absolutely recommended for your Flex projects. Three common source control solutions are Subversion, CVS and Perforce.
Adding and managing SWC libraries
There are two considerations when deciding which best practice to follow when you are referencing SWC files:
Shared SWC libraries should be referenced using the Flex Library path.
This approach is useful if the SWC library is going to be updated often or is going to be used across multiple projects. To share an SWC library, it needs to be referenced using the Flex Library path.
Use the libs folder to bundle SWC libraries with your Flex project.
An advantage to using the libs folder is that there are no external dependencies tied to your application. To compile and run, you will not need to modify the Flex project properties. You should note that the libs directory is automatically added in the Flex project's Library path.
An important thing to remember is that SWC files in the libs folder are usually not automatically updated. SWCs are typically developed separately from your application, so the directory where the SWC is compiled is typically not your Flex project's libs directory.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)