The
Application class represents a Flex application. It implements the
Builder interface which allows for building the application incrementally. There are many ways to define a Flex application. The most common way is specify the location of the target source file on disk:
Application app = new Application(new File("MyApp.mxml")); Before the
Application object starts the compilation, it must be configured. The most common methods that the client calls are
setLogger(),
setConfiguration(), and
setOutput(). A logger must implement
flex2.tools.oem.Logger and use the implementation as the Logger for the compilation. The following is an example
Logger implementation:
app.setLogger(new flex2.tools.oem.Logger() { public void log(Message message, int errorCode, String source) { System.out.println(message); } }); To specify compiler options for the
Application object, the client must get a
Configuration object populated with default values. Then, the client can set compiler options programmatically. The
setOutput() method lets clients specify where the
Application object should write the output to. If you call the
setOutput() method, the
build(boolean) method builds and writes directly to the location specified by the
setOutput() method. For example:
app.setOutput(new File("MyApp.swf")); app.build(true); If you do not call the
setOutput() method, the client can use the
build(OutputStream, boolean) method which requires the client to provide a buffered output stream. For example:
app.build(new BufferedOutputStream(new FileOutputStream("MyApp.swf")), true); Before the
Application object is thrown away, it is possible to save the compilation data for reuse by using the
save(OutputStream) method. Subsequent compilations can use the
load(OutputStream) method to get the old data into the
Application object.
app.save(new BufferedOutputStream(new FileOutputStream("MyApp.incr"))); When a cache file (such as
MyApp.incr) is available from a previous compilation, the client can call the
load(OutputStream) method before calling the
build(boolean) method. For example:
app.load(new BufferedInputStream(FileInputStream("MyApp.incr"))); app.build(); The
build(false) and
build(OutputStream, false) methods always rebuild the application. If the
Application object is new, the first
build(true)/build(OutputStream, true) method call performs a full build, which is equivalent to
build(false)/build(OutputStream, false), respectively. After a call to the
clean() method, the
Application object always performs a full build.
The clean() method not only cleans up compilation data in the Application object, but also the output file if the setOutput() method was called.
The Application class also supports building applications from a combination of source files from the file system and in-memory, dynamically-generated source objects. The client must use the Application(String, VirtualLocalFile) or Application(String, VirtualLocalFile[]) constructors.
The Application class can be part of a Project. For more information, see the Project class's description.
@see flex2.tools.oem.Configuration
@see flex2.tools.oem.Project
@version 2.0.1
@author Clement Wong