1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Hệ điều hành >

3  Set Compiler Options in Flash Builder

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (8.09 MB, 764 trang )


Solution

Set the options for the compiler arguments in the Flex Compiler screen of the Project

Properties dialog box.



Discussion

The MXML compiler, also called mxmlc, is the application that compiles ActionScript

and MXML files into a SWF file that can be viewed in the Flash Player. When you run

or debug a Flex application in Flash Builder, the MXML compiler is invoked and the

files are passed to the compiler as an argument to the application. When you debug

the player, an argument to create a debug SWF is passed to the MXML compiler. Flash

Builder lets you pass other arguments to the compiler, as well; for example, you can

pass arguments to specify the location of an external library path, allow the SWF to

access local files, or set the color of the background.

To change the compiler settings for a project, right-click or Ctrl-click (Mac) on the

project and select Properties from the contextual menu (Figure 1-8), or choose

Project→Properties from the menu bar.



Figure 1-8. Changing the properties of a project



In the resulting Project Properties dialog box (Figure 1-9), select Flex Compiler. Here

you have several options to control how the SWF file is compiled. In the input field

labeled Additional Compiler Arguments, you can add multiple options; simply type a

hyphen (-) in front of each option and separate the options with spaces.

10 | Chapter 1: Flex and ActionScript Basics



www.it-ebooks.info



Figure 1-9. Setting compiler options



Some of the most commonly used options are as follows:

verbose-stacktraces



Specifies whether the SWF will include line numbers and filenames when a runtime

error occurs. This makes the generated SWF larger. Note that a SWF with verbosestacktraces enabled is not the same as a debug SWF.

source-path path-element



Specifies directories or files to be added to the source path that contain MXML or

ActionScript you want included. You can use wildcards to include all files and

subdirectories of a directory. Also, you can use += to append the new argument to

the default options or any options set in a configuration file. For example:

-source-path+=/Users/base/Project



include-libraries



Specifies a SWC file to be compiled into the application and links all the classes

and assets in the library into the SWF. This option is useful if the application will

load in other modules that may need access to the classes in a SWC that the SWF

will not be using.

library-path



Similar to the include-libraries option but includes only classes and assets that

are used in the SWF. This lets you keep the size of the SWF file manageable.

1.3 Set Compiler Options in Flash Builder | 11



www.it-ebooks.info



locale



Specifies a locale to be associated with a SWF file. For example, you can use

-locale=es_ES to specify that the SWF is localized for Spanish.

use-network



Indicates whether the SWF will have access to the local filesystem and is intended

for use on a local machine, or whether the standard Flash Player security will apply.

For example, use -use-network=false to specify that the SWF will have local filesystem access but will not be able to use any network services. The default value

is true.

frames.frame



Enables you to add asset factories that stream in after the application and then

publish their interfaces with the ModuleManager class. The advantage of doing this

is that the application starts faster than it would have if the assets had been included

in the code, but it does not require moving the assets to a external SWF file.

keep-all-type-selectors



Ensures that all style information, even if it is not used in the application, is

compiled into the SWF. This is important if the application will be loading other

components that require style information. The default value is false, which means

that style information not used in the application is not compiled into the SWF.

After setting the options for the compiler, click the Apply button to save the options

for that project.



1.4 Compile a Flex Project Without Flash Builder

Problem

You are not using Flash Builder for your Flex project, and you need to compile your

project.



Solution

Use a terminal window or command prompt to invoke the MXML compiler.



Discussion

Although Flash Builder is a powerful tool for Flex development, it is certainly not a

requirement for creating Flex applications. The MXML compiler (mxmlc) is free to

anyone and can be downloaded from the Adobe website. To compile a Flex application

outside of Flash Builder, open a command prompt (Windows) or a terminal window

(Mac OS X), invoke the MXML compiler, and pass the file containing the application

as an argument, using a command such as the following:

home:base$. /Users/base/Flex SDK 4/bin/mxmlc ~/Documents/FlexTest/FlexTest.mxml



12 | Chapter 1: Flex and ActionScript Basics



www.it-ebooks.info



This will compile the MXML file into a SWF that by default resides in the folder where

the MXML file is located. Any warnings or errors from the compiler will be displayed

in the terminal or command-prompt window. To add further options to the MXML

compiler, you append arguments to the call to the compiler. For example, this

command:

home:base$ ./mxmlc ~/Documents/FlexTest/FlexTest.mxml

-output=/Users/base/test/generated/Index.swf -library-path+=/Users/lib/MyLib.swc



generates a SWF file named Index.swf, places it in the directory at /Users/base/test/

generated/, and includes the SWC library /Users/lib/MyLib.swc.

To invoke the MXML compiler directly from the command line without providing the

full path to your SDK installation (which in this example is C:\flex_sdk_4), you will

need to add the /bin directory the compiler resides into the Path systems variable. On

a Windows machine, do the following:

1.

2.

3.

4.

5.



Open System from the Control Panel.

Select the Advanced tab.

Click Environment Variables.

Within the System variables grid, navigate to and double-click Path.

In the Variable Value field, if the last character is not set to a semicolon (;), enter

a semicolon and then the path to the /bin folder within your Flex SDK installation

directory.

6. With the path to the MXML compiler directory set, open a command prompt,

navigate to your project directory, and enter the following command:

C:\Documents\FlexTest> mxmlc FlexTest.mxml



This generates the FlexTest.swf file within C:\Documents\FlexTest, just as the first

command presented in this section does. Setting the path to the /bin directory of

the Flex 4 SDK installation lets you invoke the compiler from any directory, including, in this example, your current project directory.

7. If step 6 results in the following error message:

Error: could not find JVM



you must manually enter the path to the directory in which the Java Runtime Environment (JRE) is installed on your machine. To manually enter the path, navigate

to the /bin directory of your Flex 4 SDK installation, open the jvm.config file in a

text editor, and append the path to your JRE installation directory to the variable

java.home. Assuming the Java installation is on the root of your drive, you would

enter the following:

java.home=C:/Java/jre



1.4 Compile a Flex Project Without Flash Builder | 13



www.it-ebooks.info



Xem Thêm
Tải bản đầy đủ (.pdf) (764 trang)

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×