Search Flex Samples

Managing project resources

Projects consist of resources (folders and files) that you can manage from the Flex Navigator view. Projects are contained within a workspace, which is a reflection of the file system. The Flex Navigator view is refreshed each time you add, delete, or modify a resource.

You can also edit project resources outside Flex Builder and the Flex Navigator view, directly in the file system.

Creating folders and files in a project

You can add folders and files to your project as needed. For example, you might create a folder to store all of your data models or to organize all the assets that make up the visual design of your application, as the following example shows:

Flex Navigator: folders and files

Create a folder

  1. In Flex Navigator view select File > New > Folder.
  2. If you have multiple projects in your workspace, select the project to add to the stand-alone folder.

    If the folder is in a source path folder, it is treated like a package name and you can place source files inside that will be recognized by the compiler.

    If the folder is not in a source path folder, you can make it the root of a package structure by adding it to your source path. To do this, select Project > Properties > Flex Build Paths.

  3. Enter the folder name and click Finish.

Create a file

  1. In the Flex Navigator view, select File > New > File.
  2. If you have multiple projects in your workspace, select the project to which you want to add the file.
  3. Enter the filename and click Finish.

You can also add folders and files that are located outside the current project; for more information, see Linking to resources outside the project workspace.

Deleting folders and files

Deleting folders and files from your project removes them from the workspace and, therefore, from the file system.

Note: If you delete a linked resource, you delete only the link from your project, not the resource itself (see Linking to resources outside the project workspace). However, if you've linked to a folder and you delete any of the files in it, they are removed from the file system.
  1. In the Flex Navigator view, select the resource to delete.
  2. Select Edit > Delete or press the Delete key, and click OK.

    The resource is deleted from the file system.

Moving resources between projects in a workspace

When you work with multiple projects in a workspace, you can move resources from one project to another.

  1. In the Flex Navigator view, select the resource to move.
  2. Do one of the following:
    • Drag the resource to a new project.
    • Cut and paste the resource to another project.

Note: You can move both normal resources and linked resources. For information about linking resources, see Linking to resources outside the project workspace.

Refreshing resources in the workspace

You can also edit resources outside Flex Builder, directly in the file system. These changes are visible only inside Flex Builder after you refresh the workspace.

By default, in the stand-alone configuration of Flex Builder, the workspace is refreshed automatically. This option is available in the Flex Builder preferences dialog box, which you can access by selecting Window > Preferences > General > Workspace. You can also change the Flex Builder default behavior so that it never refreshes the workspace automatically.

Manually refresh the workspace

In the Flex Navigator view, right-click (Control-click on Macintosh) and select Refresh from the context menu. All project resources in the workspace are refreshed.

Turn off the automatic refresh preference

  1. Select Window > Preferences > General > Workspace.
  2. Deselect Refresh Automatically.

Linking to resources outside the project workspace

You can create links to resources outside the project and workspace location. You can link to folders and files anywhere on the file system. This option is useful when you have resources that are shared between your projects. For example, you can share a library of custom Flex components or ActionScript files among many different Flex projects.

Folders that contain linked resources are marked in the Flex Navigator view (as the following example shows), so that you can distinguish between normal and linked resources.

Linking to resources

Other examples for linking resources include a folder of image file assets, or situations when the output folder is not in the project root folder.

When you work with shared resources, the changes you make to the source folders and files affect all of the projects that are linked to them. Be cautious when you delete linked resources from your projects; in some cases you merely delete the link reference, and in others you delete the source itself. For more information, see Deleting folders and files.

Note: A best practice is to link other projects to your Library Project. Linked resources should only be encouraged for third-party libraries with an SWC file.

Link to resources outside the project workspace

  1. In the Flex Navigator view, select the project to add linked resources to.
  2. Select File > New > Folder (or File).
  3. Select the project or project folder to add the linked resources to.
  4. Enter the folder or filename. The folder or filename you enter can be different from the name of the folder or file you are linking to.
  5. Click the Advanced button.
  6. Select Link to folder in the file system. Enter or browse to the resource location.
  7. Click Finish to link the resource to your project.

Using a path variable to link to resources

Rather than linking to resources by entering the full path to the local or network folder where you store your files, you can define path variables. For more information, see Creating a path variable.

  1. In the Flex Navigator view, select the project to add linked resources to.

Path variables can also be used in certain project settings, such as the library path and source path.
  1. Select File > New > Folder (or File if you want to add files).
  2. Select the project or project folder to add the linked resources to.
  3. Click the Advanced button to display the advanced options.
  4. Select Link to folder in the file system. Click the Variables button.
  5. Select a defined path variable, or click New to create a path variable.

    If you selected a defined path variable, skip to step 9. If you clicked New, you'll see the New Variable dialog box.

  6. Enter the path variable name and enter or browse to the file or folder location.

    Click OK to create the path variable.

  7. Select the new path variable in the Select Path Variable dialog box and click OK.
  8. Click Finish to complete the link to the resource.

You can also define and manage path variables by using the Flex Builder workbench preferences (Window > Preferences > General > Workspace > Linked Resources).

Adding resource folders to the project source path

To share resources between projects, place all shared resources into folders that can then be linked to each project by using the project's source path. This is the best method for using shared resources such as classes, MXML components, and images. Updates to these resources are immediately available to all projects that use them. When your projects are compiled, the shared resources are added to the SWC file.

Add an external resource folder to the source path

  1. Select the project in the Flex Navigator view.
  2. Select Project > Properties > Flex Build Path (or ActionScript Build Path if you are working with an ActionScript project).
  3. On the build path properties page, select the Source Path tab.
  4. Click the Add Folder button.
  5. Enter or and browse to the folder's path, and click OK.

    The folder is added to the source path.

You can also use the Source Path properties tab to edit, delete, or reorder items in the source path.

Folders that are added to the source path are marked in the Flex Navigator view.

Alternatives to using project references

Project references can impact build order, so Flex Builder provides alternatives to using project references.

Flex Library projects The preferred way to create a reusable library. Flex Builder creates a project reference to ensure that the SWC project is built before the main project that includes it on the library path. Also, because Flex Builder adds it to the library path, code hints appear in the main project for the classes in the SWC project.

Source path The recommended way to include code in your project that is not under the same folder structure. This enables code hints in the project files and classes in related files, and the compiler knows where to find the source code. You can add any number of source paths to your project and they are displayed as linked folders in the Flex Navigator view.

Viewing resource properties

When you work in the Flex Navigator view, you can select a resource and view its properties.

  1. In the Flex Navigator view, select a resource.
  2. Select File > Properties or press Alt+Enter (Option+Enter on Macintosh).


Related Flex Samples

Learn Flex: Flex Samples | Flex Video Tutorials Flex Examples