Flex 3 Cookbook: Chapter 21, Compiling and Debugging
Pages: 1, 2, 3, 4
Note that both actual command-line calls to the compilers use a configuration.xml file containing information about the location of the runtime shared libraries that will be passed to mxmlc:
<flex-config>
<compiler>
<external-library-path>
<path-element>example.swc</path-element>
</external-library-path>
</compiler>
<file-specs>
<path-element>RSLClientTest.mxml</path-element>
</file-specs>
<runtime-shared-libraries>
<url>example.swf</url>
</runtime-shared-libraries>
</flex-config>
In place of adding the external-library-path flag to the
command-line invocation of mxmlc as shown here
mxmlc -external-library-path=example.swc
the configuration.xml file is passed as the load-config flag in the call to the
compiler, and each option is read from the XML file.
A similar file can be passed to compc:
<flex-config>
<compiler>
<source-path>
<path-element>.</path-element>
</source-path>
</compiler>
<output>example.swc</output>
<include-classes>
<class>oreilly.cookbook.shared.*</class>
</include-classes>
</flex-config>
The complete Ant file for this recipe is shown here:
<?xml version="1.0"?>
<project name="useRSL" basedir="./">
<property name="mxmlc" value="C:\FlexSDK\bin\mxmlc.exe"/>
<property name="compc" value="C:\FlexSDK\bin\compc.exe"/>
<target name="compileRSL">
<exec executable="${compc}">
<arg line="-load-config+=rsl/configuration.xml" />
</exec>
<mkdir dir="application/rsl" />
<move file="example.swc" todir="application/rsl" />
<unzip src="application/rsl/example.swc" dest="application/rsl/" />
</target>
<target name="compileApplication">
<exec executable="${mxmlc}">
<arg line="-load-config+=application/configuration.xml" />
</exec>
</target>
<target name="compileAll" depends="compileRSL,compileApplication">
</target>
</project>
You want to track the changes to a value in your Flex application as the application executes.
Use the Flex Builder Debugger to run your application and set a breakpoint where the variable that you would like to inspect is within scope. In the Expressions window of the Flex Builder Debugger, create a new expression.
The use of expressions is a powerful debugging tool that lets you see the value of any variable within scope. Any object within the scope where the breakpoint is set can be evaluated by creating an expression, as shown in Figure 21-2.
For example, if you place a breakpoint at the line where the array is instantiated, marked here with breakpoint here
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var arr:ArrayCollection;
private function init():void {
arr = new ArrayCollection([1, 2, 3, 4, 5]);//breakpoint here
}
private function newFunc():void {
var newArr:ArrayCollection = new ArrayCollection([3, 4, 5, 6]);
}
]]>
</mx:Script>
</mx:Canvas>
This excerpt is from Flex 3 Cookbook. This highly practical book contains more than 300 proven recipes for developing interactive Rich Internet Applications and Web 2.0 sites. You'll find everything from Flex basics and working with menus and controls, to methods for compiling, deploying, and configuring Flex applications. Each recipe features a discussion of how and why it works, and many of them offer sample code that you can put to use immediately.
the expression arr will
evaluate to null. When you advance
the application by pressing the F6 key, the expression will evaluate
to an ArrayCollection wrapping an
Array of five integers (Figure 21-3).
The expression newArr
evaluates to null, however, because
the variable newArr will not be in
scope (Figure 21-4).
If you instead place a breakpoint at line 17, the expressions
newArr and arr both evaluate to ArrayCollections, because both variables
will be in the current scope
Contributed by Ryan Taylor
You can’t find the Ant view in the stand-alone version of Flex Builder.
Install the Eclipse Java Development Tools.
To access Ant in Flex Builder’s stand-alone version, you must install the Eclipse Java Development Tools. To do so:
You can now find the Ant view in Flex Builder by browsing to Window → Other Views → Ant
Contributed by Ryan Taylor
You want to leverage the capabilities of Ant to help automate common tasks such as compiling and generating documentation.
Create an Ant build file in which tasks can be added for automating your processes.
Creating an Ant build file is easy and the first step toward using Ant to automate common tasks. Simply create a new XML document named build.xml and save it in a directory named build in the root of your project directory. Saving the file in this directory is not mandatory, but a common convention.
The root node in your build file should look something like this:
<project name="MyAntTasks" basedir=".."> </project>
You will want to set the name
attribute to something unique for your project. This is the name that
will show up inside the Ant view in Eclipse. For the basedir attribute, make sure it is set to
the root of your project directory. You will use the basedir property frequently when defining
other properties that point toward files and directories inside your
project folder.
Next, you will likely want to create some additional properties for use throughout the various tasks that you may add later. For instance, to create a property that points toward your project’s source folder, you could do something like this:
<project name="MyAntTasks" basedir="..">
<property name="src" value="${basedir}/src" />
</project>
The preceding example also demonstrates how to use a property
after it has been defined, with the syntax ${property}.
If you find that you are defining a lot of properties and you would like to keep your build file as clean as possible, you can declare properties in a separate file instead. To do this, create a new text file named build.properties and save it in the same directory as your build.xml file. Inside this file, declaring properties is as simple as this:
src="${basedir}/src"
That’s all there is to it. Some examples of useful properties to define are paths to your source folder(s), your bin folder, and the Flex 3 SDK directory. You’ll catch on pretty quickly to what you need. From here, you are ready to start adding tasks to your build file.
Recipe 21.3
Contributed by Ryan Taylor
You want to add tasks to your Ant build file for compiling your application.
Add executable tasks to your Ant build file that use the MXML compiler to compile your files.
Compiling targets are by far the most common and useful types of targets you will add to your Ant build files. Flex applications are compiled by using mxmlc, which is the free command-line compiler included with the Flex 3 SDK. By adding targets for compiling to your build file, you can automate the build process: Ant will compile all your files without you ever having to open up the command prompt or terminal.
The MXML compiler (mxmlc) included in multiple formats. You can use the executable version of it by creating a target similar to this:
<!-- COMPILE MAIN -->
<target name="compileMain" description="Compiles the main application files.">
<echo>Compiling '${bin.dir}/main.swf'...</echo>
<exec executable="${FLEX_HOME}/bin/mxmlc.exe" spawn="false">
<arg line="-source-path '${src.dir}'" />
<arg line="-library-path '${FLEX_HOME}/frameworks'" />
<arg line="'${src.dir}/main.mxml'" />
<arg line="-output '${bin.dir}/main.swf'" />
</exec>
</target>