Publishing application source code

When your applications are ready to be released, you have the option of allowing users to view your application's source code and assets. As with HTML, users can access and view the source in a web browser by selecting View Source from the context menu. The source viewer formats and colors the code so that it is easy to read. Allowing source viewing is a convenient way to share code with other Flex and ActionScript 3.0 developers.

To publish an application:

  1. With the completed application project open in the editor, select Project > Publish Application Source. The Publish Application Source dialog box appears:


    Publish Application Source dialog box

  2. Select the application file that will include the View Source menu. By default, the main application file is selected.
  3. Uncheck the source files that you do not want to be published.
  4. (Optional) Change the source output folder. By default, a source view folder is added to the project's output folder.
  5. Click OK.

When users run your application, they can access the source code by selecting View Source from the context menu. The source code appears in the default web browser as a source tree that reflects the structure of the resources (packages, folders, and files) contained in your application (the ones which you decided to publish). Selecting a source element displays the code in the browser. Users can also download the entire set of source files by selecting the Download.zip file link.

NOTE

 

Because of Internet Explorer security restrictions, you may not be able to view the source on your local development computer. If this is the case, you will need to deploy the application to a web server to view the source.

Adding the view source menu to ActionScript projects

In Flex projects, you add the View Source menu option to your application using the Publish Application Source dialog box (see the preceding section). In ActionScript applications, you must add this option manually.

The Flex framework contains the following function that you can use in an ActionScript application's constructor to enable the view source menu:

com.adobe.viewsource.ViewSource.addMenuItem(obj:InteractiveObject, url:String, hideBuiltins:Boolean = true)

You can use this in your ActionScript applications as shown here:

package {
    import flash.display.MovieClip;
    import com.adobe.viewsource.ViewSource;

    public class MyASApp extends MovieClip
    {
        public function MyASApp()
        {
            ViewSource.addMenuItem(this, "srcview/index.html");

            // ... additional application code here
        }
    }

}

This example demonstrates adding the view source menu using the default location of the source folder (srcview). If you've changed the location of the source folder, your code should use the correct location.


Flex 2.01

Take a survey