Adobe Oem_guide Flex 3.0 Compiler API 3

User Manual: adobe Adobe Flex - 3.0 - Compiler API Free User Guide for Adobe Flex Software, Manual

Open the PDF directly: View PDF PDF.
Page Count: 24

DownloadAdobe Oem_guide Flex - 3.0 Compiler API 3
Open PDF In BrowserView PDF
COMPILER API USER GUIDE

© 2008 Adobe Systems Incorporated. All rights reserved.
Adobe® Flex® 3 Compiler API User Guide
If this guide is distributed with software that includes an end-user agreement, this guide, as well as the software described in it, is furnished under license and may be used or
copied only in accordance with the terms of such license. Except as permitted by any such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note that the
content in this guide is protected under copyright law even if it is not distributed with software that includes an end-user license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorized incorporation of such
material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required from the copyright owner.
Adobe, the Adobe logo, Flex, and Flex Builder are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries.
ActiveX and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries.
All other trademarks are the property of their respective owners.
This product includes software developed by the Apache Software Foundation (http://www.apache.org/).
This product contains either BISAFE and/or TIPEM software by RSA Data Security, Inc.
The Flex Builder 3 software contains code provided by the Eclipse Foundation (“Eclipse Code”). The source code for the Eclipse Code as contained in Flex Builder 3 software
(“Eclipse Source Code”) is made available under the terms of the Eclipse Public License v1.0 which is provided herein, and is also available at http://www.eclipse.org/legal/eplv10.html.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA.
Notice to U.S. government end users. The software and documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of “Commercial Computer
Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as applicable. Consistent with 48 C.F.R.
§12.212 or 48 C.F.R. §§227.7202-1 through 227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being
licensed to U.S. Government end users (a) only as Commercial items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions
herein. Unpublished-rights reserved under the copyright laws of the United States. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity
laws including, if appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance Act of 1974 (38 USC 4212),
and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60, 60-250 ,and 60-741. The affirmative action clause and
regulations contained in the preceding sentence shall be incorporated by reference.
Part Number: (12/06)

iii

Contents
Chapter 1: Introduction
About the Flex compiler API
Quick Start

............................................................... 1

............................................................................... 2

Configuring the compiler

................................................................. 4

Adding assets to applications

............................................................. 5

Chapter 2: Logging and Reports
Using custom logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Creating reports
Watching progress

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Chapter 3: Libraries and Projects
Creating libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Creating projects

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Chapter 4: Creating Dynamic Applications
About the creation of dynamic applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Using custom components

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Using incremental compilation

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

1

Chapter 1: Introduction
The Quick Start section contains a full example to get you started using the Adobe® Flex® compiler API.
Topics

About the Flex compiler API. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Configuring the compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Adding assets to applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

About the Flex compiler API
The Flex compiler API lets you compile Flex applications from Java applications. You can also create Flex applications in memory and compile them to SWF files without ever having an MXML file on disk. In addition, the compiler
API lets you output linkage reports and other details about your applications.
You can also create project files and libraries with the compiler API. Libraries are SWC files that define a set of
components for use in your application, theme files, or Runtime Shared Libraries (RSLs). Projects combine Flex
applications and libraries. They let you enforce dependencies between a Flex application and its assets in the compilation process.

Requirements of the compiler API
The Flex compiler API has the following requirements:
Java JDK The compiler API requires that you have the Java interpreter and the javac compiler from JDK version 1.4.2

or later.
Flex SDK The compiler API is not a stand-alone product. It requires the Flex SDK or the SDK included with Flex

Builder.

What’s included
The flex_compiler_api.zip file includes the following resources:
flex-compiler-oem.jar The flex2.tools.oem.* API for the compiler API. This JAR file is in the /lib directory in the
ZIP file. When you expand the ZIP file, you should move this file to your SDK’s lib directory.
JavaDocs The API documentation for the public classes and interfaces in the flex2.tools.oem.* package. These files

are in the /api directory in the ZIP file.
README.txt The readme file is at the top level of the ZIP file. It contains installation instructions and information

on using a temporary license with the compiler API.
In addition, you can download the following separately:
flex_compiler_api_guide.pdf The Flex 3 Compiler API User Guide is a PDF that provides usage documentation for
the compiler API. This file is at the top level of the ZIP file.

ADOBE FLEX 3 2
Adobe Flex 3 Compiler API User Guide

Quick Start
The following example describes how to create a simple Java application that compiles a Flex application.
Create and compile a new application with the compiler API

Extract the contents of the flex_compiler_api.zip file and copy the flex-oem-compiler.jar file to your SDK’s lib
directory. For the Flex SDK, this directory is located at sdk_root/lib. For Flex Builder users, this directory is located
at flex_builder_root/sdks/3.0.0/lib.

1

2

Create a Java application; for example, MyAppCompiler.java:
// java/MyAppCompiler.java
import flex2.tools.oem.Application;
import java.io.*;
public class MyAppCompiler {
public static void main(String[] args) {
try {
Application application = new Application(new File("../apps/TestApp.mxml"));
application.setOutput(new File("../apps/TestApp.swf"));
long result = application.build(true);
if (result > 0) {
System.out.println("COMPILE OK");
} else {
System.out.println("COMPILE FAILED");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

In this file, ensure that you do the following:

3

a

Create an Application object.

b

Specify an output file for the new Application object.

c

Call the Application.build() method.

d

Check for a value greater than 0 returned by the build() method.

Compile the class with your Java compiler; for example:
C:\myapps\src>javac -classpath c:\flex\lib\flex-compiler-oem.jar MyAppCompiler.java

Ensure that you add the flex-compiler-oem.jar to your Java classpath.
Create an MXML file and store it in the location you specified with the File constructor in your Java application;
for example, create a file named TestApp.mxml in the myapps\apps directory:

4






5

Run the new application compiler with your Java interpreter; for example:
C:\myapps\src>java -classpath c:\flex\lib\flex-compiler-oem.jar;. MyAppCompiler

Ensure that you add the flex-compiler-oem.jar, and the current directory, to your Java classpath.
You can set configuration options in your Java application by using the Configuration class’s methods. The following
example enables the ActionScript optimizer and disables compiler warnings:
// java/MyConfiguringCompiler.java

ADOBE FLEX 3 3
Adobe Flex 3 Compiler API User Guide

import flex2.tools.oem.Application;
import flex2.tools.oem.Configuration;
import java.io.*;
public class MyConfiguringCompiler {
public static void main(String[] args) {
String outputRoot = "../apps/";
try {
Application application = new Application(new
File(outputRoot, "ErrorTestApp.mxml"));
application.setOutput(new File(outputRoot, "ErrorTestApp.swf"));
Configuration config = application.getDefaultConfiguration();
// Enable ActionScript optimizer.
config.optimize(true);
// Disable warnings.
config.showActionScriptWarnings(false);
config.showBindingWarnings(false);
config.showUnusedTypeSelectorWarnings(false);
// Apply the new configuration to the Application.
application.setConfiguration(config);
long result = application.build(true);
if (result > 0) {
System.out.println("COMPILE OK");
} else {
System.out.println("COMPILE FAILED");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

To compile data visualization applications without a watermark, you must pass a valid Flex Builder Professional
license key to your application. You can do this with the Configuration class’s setLicense() method. The following
example sets the license key prior to launching the compiler:
// java/MyDataVisAppCompiler.java
import flex2.tools.oem.Application;
import flex2.tools.oem.Configuration;
import java.io.*;
public class MyDataVisAppCompiler {
public static void main(String[] args) {
try {
Application application = new Application(new
File("../apps/DataVisTestApp.mxml"));
application.setOutput(new File("../apps/DataVisTestApp.swf"));
// Get an instance of the default configuration class.
Configuration config = application.getDefaultConfiguration();
// Replace this with a valid license key.
config.setLicense("flexbuilder3", "0000-0000-0000-0000-0000-0000");
// Apply the new configuration to the Application.
application.setConfiguration(config);

ADOBE FLEX 3 4
Adobe Flex 3 Compiler API User Guide

long result = application.build(true);
if (result > 0) {
System.out.println("COMPILE OK");
} else {
System.out.println("COMPILE FAILED");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

Configuring the compiler
You can pass configuration options to the compiler when using the compiler API. To do this, you get an instance of
the Configuration class using the Application or Library classes’s getDefaultConfiguration() method, set the
options on that instance, and then assign that object to the Application or Library by using the
setConfiguration() method.
For most compiler options, there is a 1:1 mapping between the flex2.tools.oem.Configuration API methods and the
compiler options. For example, to set the value of the keep-generated-actionscript compiler option to true,
you pass true to the Configuration class’s keepCompilerGeneratedActionScript() method:
config.keepCompilerGeneratedActionScript(true);

Some compiler options, such as source-path and library-path, can use the += operator to append entries to the
source path and library path. For these compiler options, you can replace the entire path using the
setSourcePath() and setLibraryPath() methods, or you can append new entries to the list with the
addSourcePath() and addLibraryPath() methods.
In some cases, the Configuration class does not have a method that maps to a compiler option. You might call a
method of a different class, or call multiple methods. For example, there is no method in the compiler API that
enables and disables all warnings as per the warnings compiler option. Instead, you call the
showActionScriptWarnings() , showBindingWarnings(), showShadowedDeviceFontWarnings(), and
showUnusedTypeSelectorWarnings() methods.
The following table lists the compiler options that have alternative methods for setting their values:
Compiler option

Equivalent compiler API method or methods

dump-config

Call the Configuration.keepConfigurationReport(true) method and then the
Report.writeConfigurationReport() method.

include-classes

Call the Library.addComponent(java.lang.String) method.

include-file

Call the Library.addArchiveFile() method.

include-namespaces

Call the Library.addComponent(java.net.URI) method.

include-sources

Call the Library.addComponent(VirtualLocalFile) or
Library.addComponent(java.io.File) method.

library-path

Call the Configuration.setLibraryPath() method to replace the value of the default source
path. Call the Configuration.addLibraryPath() method to append new values to the default
source path.

link-report

Call the Configuration.keepLinkReport(true) method, then the
Report.writeLinkReport() method.

ADOBE FLEX 3 5
Adobe Flex 3 Compiler API User Guide

Compiler option

Equivalent compiler API method or methods

output

Call the Application.setOutput() and Library.setOutput()/setDirectory() methods.

resource-bundle-list

Call the Report.getResourceBundleNames() method.

source-path

Call the Configuration.setSourcePath() method to replace the value of the default source
path. Call the Configuration.addSourcePath() method to append new values to the default
source path.

version

Call the Report.getCompilerVersion() method.

warnings

Call the showActionScriptWarnings(), showBindingWarnings(),
showShadowedDeviceFontWarnings(), and showUnusedTypeSelectorWarnings()
methods.

About option and property precedence
Similar to mxmlc and compc, the default configuration that the compiler API uses is the flex-config.xml file. For
compiling applications, the compiler API also uses local configuration files. The compiler API then applies the
configuration options in flex2.tools.oem.Configuration to create the final set of compiler configuration options.
By default, the compiler invoked by the compiler API populates the default Configuration object with options in the
flex-config.xml file. This file’s location is relative to the location of the mxmlc.jar file. In most cases, this file is in the
SDK’s lib directory, which is the same directory that contains the flex-compiler-oem.jar file. The compiler also uses
local configuration files (such as app_name-config.xml), or you can point to the location of another configuration
file using the Configuration class’s addConfiguration() method.
Configuration options that you set with the compiler API have the same precedence as a command-line compiler
option. This means that they take precedence over all other options (flex-config.xml, alternative configuration file,
and local configuration file).
For more information about using configuration files, see “Using the Flex Compilers” on page 125 in Building and
Deploying Flex Applications.

Clearing configurations
You can clear a configuration by calling the Application.setConguration(null) method.

Adding assets to applications
You can add assets to the application by using methods of the Configuration class, such as addExterns() ,
addIncludes() , and setTheme(). Using these methods, you can add external themes, libraries, classes, RSLs, and
other types of assets.
The following example uses the Configuration class’s setTheme() method to add a theme to the resulting application:
// java/MyThemeCompiler.java
import flex2.tools.oem.Application;
import flex2.tools.oem.Configuration;
import java.io.*;
public class MyThemeCompiler {
public static void main(String[] args) {
String assetRoot = "../assets/";
String outputRoot = "../apps/";

ADOBE FLEX 3 6
Adobe Flex 3 Compiler API User Guide

try {
File[] themeFile = new File[]
{new File(assetRoot, "myTheme.css")};
Application application = new Application(new File(outputRoot,
"TestAppWithAssets.mxml"));
application.setOutput(new File(outputRoot, "TestAppWithAssets.swf"));
Configuration config = application.getDefaultConfiguration();
config.setTheme(themeFile);
application.setConfiguration(config);
long result = application.build(true);
if (result > 0) {
System.out.println("COMPILE OK");
} else {
System.out.println("COMPILE FAILED");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

To add a SWC file that contains components, use the addLibraryPath() method. In the following example, the
assets directory contains the MyComponents.swc file:
// java/MyLibraryPathCompiler.java
import flex2.tools.oem.Application;
import flex2.tools.oem.Configuration;
import java.io.*;
public class MyLibraryPathCompiler {
public static void main(String[] args) {
String assetRoot = "../assets/";
String outputRoot = "../apps/";
try {
Application application = new Application(new
File(outputRoot, "TestAppWithAllAssets.mxml"));
application.setOutput(new
File(outputRoot, "TestAppWithAllAssets.swf"));
Configuration config = application.getDefaultConfiguration();
File[] libFile = new File[]
{new File(assetRoot, "MyComponents.swc")};
config.addLibraryPath(libFile);
application.setConfiguration(config);
long result = application.build(true);
if (result > 0) {
System.out.println("COMPILE OK");
} else {
System.out.println("COMPILE FAILED");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

ADOBE FLEX 3 7
Adobe Flex 3 Compiler API User Guide

To add a directory that contains MXML or ActionScript component files that are not in a SWC file, use the
addSourcePath() method. In the following example, the assets directory contains several MXML files that are used
by the TestSourcePathApp application:
// java/MySourcePathAppCompiler.java
import flex2.tools.oem.Application;
import flex2.tools.oem.Configuration;
import java.io.*;
public class MySourcePathAppCompiler {
public static void main(String[] args) {
String assetRoot = "../assets/";
String outputRoot = "../apps/";
try {
File[] sourcePath = new File[] {new File(assetRoot)};
Application application = new Application(new
File(outputRoot, "TestSourcePathApp.mxml"));
application.setOutput(new
File(outputRoot, "TestSourcePathApp.swf"));
Configuration config = application.getDefaultConfiguration();
// The source path can be a directory.
// All MXML and AS files in that directory are added
// to the source path.
config.addSourcePath(sourcePath);
application.setConfiguration(config);
long result = application.build(true);
if (result > 0) {
System.out.println("COMPILE OK");
} else {
System.out.println("COMPILE FAILED");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

You can also create libraries or components with the compiler API. For more information on creating libraries, see
“Creating libraries” on page 15. To add libraries and organize their dependencies at run time, use the Project class.
For more information, see “Creating projects” on page 16.

8

Chapter 2: Logging and Reports
The Adobe Flex compiler API lets you generate reports and provide information such as progress and logs during
the compilation process.
Topics

Using custom logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Creating reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Watching progress. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Using custom logging
You can capture error messages with the compiler. To do this, you create a custom logger and assign that logger to
the applications that you are compiling.
Use a custom logger
1

Create a Java class that implements the flex2.tools.oem.Logger interface; for example:
// java/SimpleLogger.java
import flex2.tools.oem.Message;
import flex2.tools.oem.Logger;
import java.util.*;
public class SimpleLogger implements Logger {
SimpleLogger() {
System.out.println("----------------------------------");
}
public void log(Message msg, int errorCode, String source) {
System.out.println(msg);
System.out.println("----------------------------------");
}
}

This class must define the log() method, which takes three arguments: the message, the error code, and the
source.
In your Java application, call the Application instance’s setLogger() method to assign a logger to that Application; for example:
2

application.setLogger(new SimpleLogger());

If you do not call the setLogger() method, the compiler logs messages to the standard output.
3

Compile and run your example.

4

To test the logger, add one or more syntax errors to your sample Flex application; for example:




// Generates a warning because there is no return type.
public function doSomethingWrong() {
// Generates an error because x lacks a type.

ADOBE FLEX 3 9
Adobe Flex 3 Compiler API User Guide

var x;
}




This example produces output similar to the following:
---------------------------------ERROR: Loading configuration file C:\flex\sdk\frameworks\flex-config.xml
-------------------------------------------------------------------ERROR: return value for function 'doSomethingWrong' has no type declaration.
---------------------------------ERROR: variable 'x' has no type declaration.
----------------------------------

You can access other information about the error, such as the error level and the location of the error, by using the
Message class’s getLevel(), getPath(), getLine(), and getColumn() methods. The following example prints
more information than the SimpleLogger example:
// java/ComplexLogger.java
import flex2.tools.oem.Message;
import flex2.tools.oem.Logger;
import java.util.*;
import java.io.*;
public class ComplexLogger implements Logger {
ComplexLogger() {
String LOGFILENAME = "output.txt";
try {
System.setOut(new PrintStream(new FileOutputStream(LOGFILENAME)));
} catch (Exception e) {
System.out.println("There was an error creating the log file.");
}
System.out.println("Ran at : " + new Date());
System.out.println("----------------------------------");
}
public void log(Message msg, int errorCode, String source) {
if (msg.getLevel() == "info") {
// Suppress info messages.
} else {
System.out.println("ERROR : " + errorCode);
System.out.println("MESSAGE: " + msg);
System.out.println("SOURCE : " + source);
System.out.println("LEVEL : " + msg.getLevel());
System.out.println("PATH
: " + msg.getPath());
System.out.println("LINE
: " + msg.getLine());
System.out.println("COLUMN : " + msg.getColumn());
System.out.println("----------------------------------");
}
}
}

Not all compiler errors generate valid values for all properties. For example, errors in your MXML code do not
typically produce an error code, so the Logger returns a -1. ActionScript errors, however, do generate an error code.
You can also use the Report class to view Message objects when the compiler runs. For more information, see “Using
reports to view messages” on page 12.

ADOBE FLEX 3 10
Adobe Flex 3 Compiler API User Guide

Creating reports
The compiler API includes the capability to create reports about the application, library, or project that you are
compiling. In the reports, you can include details about the application’s linkage, assets, dependencies, libraries, and
resource bundles, in addition to information about the application, such as the background color, height, and width.
To get a report, you use the Application or Library object’s getReport() method. This method returns an instance
of the Report class, which you then use to output information about the target of the compilation.
Before you generate a report by using the Report class, you must build the Application or Library. This means that
you must call the build() method before you can call any reporting methods.
The following example prints report information to the standard output:
// java/MyReportCompiler.java
import flex2.tools.oem.Application;
import flex2.tools.oem.Report;
import flex2.tools.oem.Configuration;
import flex2.tools.oem.Logger;
import java.io.*;
public class MyReportCompiler {
public static void main(String[] args) {
String assetRoot = "../assets/";
String outputRoot = "../apps/";
File[] themeFile = new File[] {new File(assetRoot, "myTheme.css")};
File[] libFile = new File[] {new File(assetRoot, "MyComponents.swc")};
try {
Application application = new Application(new File(outputRoot,
"TestAppWithAllAssets.mxml"));
application.setOutput(new File(outputRoot, "TestAppWithAllAssets.swf"));
// Uncomment this line to have log entries written to a file.
//application.setLogger(new ComplexLogger());
// Uncomment this line to show progress meter.
//application.setProgressMeter(new MyProgressMeter());
Configuration config = application.getDefaultConfiguration();
config.setTheme(themeFile);
config.addLibraryPath(libFile);
application.setConfiguration(config);
application.build(true);
Report report = application.getReport();
// Lists the image files that are embedded.
System.out.println("\n\nEMBEDDED ASSETS: ");
String[] cnames = report.getAssetNames(Report.COMPILER);
for (int i=0; i tag (for example, ), and end with a closing  tag.
1

Create a VirtualLocalFile by calling the VirtualLocalFileSystem.create() method. Pass the following
parameters to the create() method:

2

name Specifies the canonical path name of the target directory, and a virtual filename. The actual name is not
usually important, but it must be in the correct location and it must have a .as or .mxml extension. The name is
important when you create a custom component that you use in your virtual application.
text
parent

Specifies the String that stores all the MXML source code for application.
Specifies the canonical filename for the target directory.

lastModified

Sets the value of the timestamp on the new virtual file. This is usually the current date and

time.
3

Create a new Application object, passing the new VirtualLocalFile object as its parameter.

4

Define the output file for the Application object.

5

Call the Application.build() method.

The following example creates an application that has a simple Button control:
// java/MyVirtualFileCompiler.java
import flex2.tools.oem.*;
import java.io.*;
public class MyVirtualFileCompiler {
public static void main(String[] args) {
try {
File parent = new File(".").getCanonicalFile();
String src = "" +
"" +

ADOBE FLEX 3 19
Adobe Flex 3 Compiler API User Guide

"";
VirtualLocalFileSystem fs = new VirtualLocalFileSystem();
VirtualLocalFile lf =
fs.create(new File(parent,"VirtualApp.mxml").getCanonicalPath(),
src, parent, System.currentTimeMillis());
Application app = new Application(lf);
app.setOutput(new File("VirtualApp.swf"));
app.build(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

Using custom components
You can create an application that uses existing custom components. You can also create the custom components
dynamically. To do this, you create multiple VirtualLocalFile objects, and pass them as an array of files to the Application object’s constructor.
The following example creates two custom components and adds them to the application:
// java/MyVirtualFilesCompiler.java
import flex2.tools.oem.*;
import java.io.*;
public class MyVirtualFilesCompiler {
public static void main(String[] args) {
try {
VirtualLocalFileSystem fs = new VirtualLocalFileSystem();
File parent = new File(".").getCanonicalFile();
String main = "" +
"" +
"" +
"" +
"" +
"";
String comp1 =
"";
String comp2 =
"";
VirtualLocalFile vlfComp1 = fs.create(new
File(parent,"MyCustomButton.mxml").getCanonicalPath(),
comp1, parent, System.currentTimeMillis());
VirtualLocalFile vlfComp2 = fs.create(new
File(parent,"MyCustomLabel.mxml").getCanonicalPath(),
comp2, parent, System.currentTimeMillis());
VirtualLocalFile vlfMain = fs.create(new
File(parent,"ComplexVirtualApp.mxml").getCanonicalPath(),
main, parent, System.currentTimeMillis());

ADOBE FLEX 3 20
Adobe Flex 3 Compiler API User Guide

// The order of arguments here matters. You must create
// the components before you can create the application
// that uses those components.
Application app = new Application(new
VirtualLocalFile[] {vlfComp1, vlfComp2, vlfMain});
app.setLogger(new ComplexLogger());
app.setOutput(new File("ComplexVirtualApp.swf"));
app.build(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

When creating an application or library that uses custom components, keep in mind the following details:
The name you provide for the name parameter of the create() method is important. It must match the name
that you use in the application. For example, if you refer to a component as , the name
must be "MyCustomComponent", as the following example shows:
1

VirtualLocalFile vlfComp1 = fs.create(new
File(parent,"MyCustomComponent").getCanonicalPath(), comp1, parent, mod);

The order of creation for components and applications is important. If your application uses custom components
or other files that are created at the same time, you must create those components before you create the application.
To ensure this, list the components before the application in the Application object’s constructor, as the following
example shows:

2

Application app = new Application(new VirtualLocalFile[] {vlfComp1, vlfComp2, vlfMain});

Using incremental compilation
You can use incremental compilation with VirtualLocalFile objects. This makes compilation more efficient because
the compiler only recompiles the virtual file that was changed and not all files that are in the application. You
typically use incremental compilation in a Java application that builds a Flex application more than once. The first
time the Flex application is built, the compiler compiles all parts of the application. On subsequent compilations, if
you use incremental compilation, the compiler only compiles the parts of the application that changed.
To trigger the use of incremental compilation, use the VirtualLocalFileSystem class’s update() method to change a
virtual local file. Then call the build() method again to compile the application incrementally.
For more information about incremental compilation, see “About incremental compilation” on page 157 in Building
and Deploying Flex Applications.
The following example calls the changeComponent() method and makes a change to one of the VirtualLocalFile
objects in it. The application then calls the fs.update() method, which updates only that virtual file with the new
code. The build() method ultimately takes less time to compile the application because only the changed code is
recompiled.
// java/MyIncrementalCompiler.java
import flex2.tools.oem.*;
import java.io.*;
public class MyIncrementalCompiler {
static Application app;
static VirtualLocalFileSystem fs;

ADOBE FLEX 3 21
Adobe Flex 3 Compiler API User Guide

static File parent;
public static void main(String[] args) {
try {
fs = new VirtualLocalFileSystem();
parent = new File(".").getCanonicalFile();
String main =
"" +
"" +
"" +
"" +
"" +
"";
String comp1 =
"";
String comp2 =
"";
VirtualLocalFile vlfComp1 =
fs.create(new File(parent,"MyCustomButton.mxml").
getCanonicalPath(), comp1, parent,
System.currentTimeMillis());
VirtualLocalFile vlfComp2 =
fs.create(new File(parent,"MyCustomLabel.mxml").
getCanonicalPath(), comp2, parent,
System.currentTimeMillis());
VirtualLocalFile vlfMain =
fs.create(new File(parent,"ComplexVirtualApp.mxml").
getCanonicalPath(), main, parent,
System.currentTimeMillis());
// The order of arguments here matters. You must create
// the components before you can create the application
// that uses those components.
app = new Application(new VirtualLocalFile[] {vlfComp1, vlfComp2, vlfMain});
app.setLogger(new ComplexLogger());
app.setOutput(new File("IncrementalVirtualApp.swf"));
app.build(true);
// Calling changeComponent() updates one of the virtual files,
// which lets you then use the update() method to use
// incremental compilation.
changeComponent();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void changeComponent() {
try {
String newComp =
"";
fs.update(new File(parent,"MyCustomButton.mxml").getCanonicalPath(), newComp,

ADOBE FLEX 3 22
Adobe Flex 3 Compiler API User Guide

System.currentTimeMillis());
app.build(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.4
Linearized                      : Yes
Tagged PDF                      : Yes
Page Mode                       : UseOutlines
XMP Toolkit                     : Adobe XMP Core 4.0-c316 44.253921, Sun Oct 01 2006 17:14:39
Format                          : application/pdf
Title                           : oem_guide.book
Creator                         : ladler
Create Date                     : 2008:02:20 11:36:23Z
Creator Tool                    : FrameMaker 7.2
Modify Date                     : 2008:02:20 11:37:25Z
Producer                        : Acrobat Distiller 8.1.0 (Windows)
Document ID                     : uuid:23850931-e50d-4577-a003-2f93fc1880ae
Instance ID                     : uuid:cdcba1ac-ea11-4db5-8bf6-343fe95bc73f
Page Count                      : 24
Author                          : ladler
EXIF Metadata provided by EXIF.tools

Navigation menu