首先:
1.下载flex的sdk,如果你电脑有装flash builder,它自带了一份,位于安装目录的sdks目录下。
备注:(sdk依赖java的jre)
2.配置mxmlc的java运行环境jre,该配置文件位于sdk/bin/jvm.config,更改java.home=jre所在目录。
3.配置mxmlc的环境变量,改环境变量exe,位于sdk/bin/mxmlc.exe,控制台输入:mxmlc,没报错证明配置成功。
注意:如果不配置,并且你之前有配置过java的jre,那么mxmlc会默认为java的jre。
然后:需要一个编译项目的配置文件flex-config .xml,该文件可以在sdk的frameworks目录可以找到。可以参考以下完整的:
<?xml version="1.0"?> ADOBE SYSTEMS INCORPORATED Copyright 2005-2007 Adobe Systems Incorporated All Rights Reserved. NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the license agreement accompanying it.--><flex-config> Specifies the minimum player version that will run the compiled SWF. --> <target-player>11.1target-player> Specifies the version of the compiled SWF --> <swf-version>14swf-version> <compiler> Turn on generation of accessible SWFs. --> <accessible>trueaccessible> Specifies the locales for internationalization. --> <locale> <locale-element>en_USlocale-element> locale> List of path elements that form the roots of ActionScript class hierarchies. --> not set --> string--> Allow the source-path to have path-elements which contain other path-elements --> <allow-source-path-overlap>falseallow-source-path-overlap> Run the AS3 compiler in a mode that detects legal but potentially incorrect --> code. --> <show-actionscript-warnings>trueshow-actionscript-warnings> Turn on generation of debuggable SWFs. False by default for mxmlc, --> but true by default for compc. --> true--> List of SWC files or directories to compile against but to omit from --> linking. --> <external-library-path> <path-element>${flexlib}/libs/player/{targetPlayerMajorVersion}.{targetPlayerMinorVersion}/playerglobal.swcpath-element> external-library-path> not set --> src/res/comlib.swc--> List of SWC files or directories that contain SWC files. --> <library-path> <path-element>${flexlib}/libspath-element> <path-element>${flexlib}/libs/mxpath-element> <path-element>${flexlib}/locale/{locale}path-element> The following entry is because LCDS copies playerfds.swc in the player folder --> <path-element>${flexlib}/libs/playerpath-element> <path-element>${flexlib}/src/respath-element> library-path> <namespaces> Specify a URI to associate with a manifest of components for use as MXML --> elements. --> <namespace> <uri>http://ns.adobe.com/mxml/2009uri> <manifest>${flexlib}/mxml-2009-manifest.xmlmanifest> namespace> <namespace> <uri>library://ns.adobe.com/flex/sparkuri> <manifest>${flexlib}/spark-manifest.xmlmanifest> namespace> <namespace> <uri>library://ns.adobe.com/flex/mxuri> <manifest>${flexlib}/mx-manifest.xmlmanifest> namespace> <namespace> <uri>http://www.adobe.com/2006/mxmluri> <manifest>${flexlib}/mxml-manifest.xmlmanifest> namespace> namespaces> Enable post-link SWF optimization. --> <optimize>trueoptimize> Enable trace statement omission. --> <omit-trace-statements>trueomit-trace-statements> Keep the following AS3 metadata in the bytecodes. --> Warning: For the data binding feature in the Flex framework to work properly, --> the following metadata must be kept: --> 1. Bindable --> 2. Managed --> 3. ChangeEvent --> 4. NonCommittingChangeEvent --> 5. Transient --> BindableManagedChangeEventNonCommittingChangeEventTransient--> Turn on reporting of data binding warnings. For example: Warning: Data binding --> will not be able to detect assignments to "foo". --> <show-binding-warnings>trueshow-binding-warnings> toggle whether warnings generated from unused type selectors are displayed --> <show-unused-type-selector-warnings>trueshow-unused-type-selector-warnings> Run the AS3 compiler in strict error checking mode. --> <strict>truestrict> Use the ActionScript 3 class based object model for greater performance and better error reporting. --> In the class based object model most built-in functions are implemented as fixed methods of classes --> (-strict is recommended, but not required, for earlier errors) --> <as3>trueas3> Use the ECMAScript edition 3 prototype based object model to allow dynamic overriding of prototype --> properties. In the prototype based object model built-in functions are implemented as dynamic --> properties of prototype objects (-strict is allowed, but may result in compiler errors for --> references to dynamic properties) --> <es>falsees> List of CSS or SWC files to apply as a theme. --> <theme> The Flex 4 default theme is Spark. --> <filename>${flexlib}/themes/Halo/halo.swcfilename> theme> Turns on the display of stack traces for uncaught runtime errors. --> <verbose-stacktraces>falseverbose-stacktraces> Defines the AS3 file encoding. --> not set --> --> <fonts> Enables advanced anti-aliasing for embedded fonts, which provides greater clarity for small --> fonts. This setting can be overriden in CSS for specific fonts. --> NOTE: flash-type has been deprecated. Please use advanced-anti-aliasingtrue--> <advanced-anti-aliasing>trueadvanced-anti-aliasing> The number of embedded font faces that are cached. --> <max-cached-fonts>20max-cached-fonts> The number of character glyph outlines to cache for each font face. --> <max-glyphs-per-face>1000max-glyphs-per-face> Defines ranges that can be used across multiple font-face declarations. --> See flash-unicode-table.xml for more examples. --> not set --> englishRangeU+0020-007E--> Compiler font manager classes, in policy resolution order--> <managers> <manager-class>flash.fonts.JREFontManagermanager-class> <manager-class>flash.fonts.BatikFontManagermanager-class> <manager-class>flash.fonts.AFEFontManagermanager-class> <manager-class>flash.fonts.CFFFontManagermanager-class> managers> File containing cached system font licensing information produced via java -cp mxmlc.jar flex2.tools.FontSnapshot (fontpath) Will default to winFonts.ser on Windows XP and macFonts.ser on Mac OS X, so is commented out by default. --> <local-fonts-snapshot>${flexlib}/localFonts.serlocal-fonts-snapshot> fonts> Array.toString() format has changed. --> <warn-array-tostring-changes>falsewarn-array-tostring-changes> Assignment within conditional. --> <warn-assignment-within-conditional>truewarn-assignment-within-conditional> Possibly invalid Array cast operation. --> <warn-bad-array-cast>truewarn-bad-array-cast> Non-Boolean value used where a Boolean value was expected. --> <warn-bad-bool-assignment>truewarn-bad-bool-assignment> Invalid Date cast operation. --> <warn-bad-date-cast>truewarn-bad-date-cast> Unknown method. --> <warn-bad-es3-type-method>truewarn-bad-es3-type-method> Unknown property. --> <warn-bad-es3-type-prop>truewarn-bad-es3-type-prop> Illogical comparison with NaN. Any comparison operation involving NaN will evaluate to false because NaN != NaN. --> <warn-bad-nan-comparison>truewarn-bad-nan-comparison> Impossible assignment to null. --> <warn-bad-null-assignment>truewarn-bad-null-assignment> Illogical comparison with null. --> <warn-bad-null-comparison>truewarn-bad-null-comparison> Illogical comparison with undefined. Only untyped variables (or variables of type *) can be undefined. --> <warn-bad-undefined-comparison>truewarn-bad-undefined-comparison> Boolean() with no arguments returns false in ActionScript 3.0. Boolean() returned undefined in ActionScript 2.0. --> <warn-boolean-constructor-with-no-args>falsewarn-boolean-constructor-with-no-args> __resolve is no longer supported. --> <warn-changes-in-resolve>falsewarn-changes-in-resolve> Class is sealed. It cannot have members added to it dynamically. --> <warn-class-is-sealed>truewarn-class-is-sealed> Constant not initialized. --> <warn-const-not-initialized>truewarn-const-not-initialized> Function used in new expression returns a value. Result will be what the --> function returns, rather than a new instance of that function. --> <warn-constructor-returns-value>falsewarn-constructor-returns-value> EventHandler was not added as a listener. --> <warn-deprecated-event-handler-error>falsewarn-deprecated-event-handler-error> Unsupported ActionScript 2.0 function. --> <warn-deprecated-function-error>truewarn-deprecated-function-error> Unsupported ActionScript 2.0 property. --> <warn-deprecated-property-error>truewarn-deprecated-property-error> More than one argument by the same name. --> <warn-duplicate-argument-names>truewarn-duplicate-argument-names> Duplicate variable definition --> <warn-duplicate-variable-def>truewarn-duplicate-variable-def> ActionScript 3.0 iterates over an object's properties within a "for x in target" statement in random order. --> <warn-for-var-in-changes>falsewarn-for-var-in-changes> Importing a package by the same name as the current class will hide that class identifier in this scope. --> <warn-import-hides-class>truewarn-import-hides-class> Use of the instanceof operator. --> <warn-instance-of-changes>truewarn-instance-of-changes> Internal error in compiler. --> <warn-internal-error>truewarn-internal-error> _level is no longer supported. For more information, see the flash.display package. --> <warn-level-not-supported>truewarn-level-not-supported> Missing namespace declaration (e.g. variable is not defined to be public, private, etc.). --> <warn-missing-namespace-decl>truewarn-missing-namespace-decl> Negative value will become a large positive value when assigned to a uint data type. --> <warn-negative-uint-literal>truewarn-negative-uint-literal> Missing constructor. --> <warn-no-constructor>falsewarn-no-constructor> The super() statement was not called within the constructor. --> <warn-no-explicit-super-call-in-constructor>falsewarn-no-explicit-super-call-in-constructor> Missing type declaration. --> <warn-no-type-decl>truewarn-no-type-decl> In ActionScript 3.0, white space is ignored and '' returns 0. Number() returns --> NaN in ActionScript 2.0 when the parameter is '' or contains white space. --> <warn-number-from-string-changes>falsewarn-number-from-string-changes> Change in scoping for the this keyword. Class methods extracted from an --> instance of a class will always resolve this back to that instance. In --> ActionScript 2.0 this is looked up dynamically based on where the method --> is invoked from. --> <warn-scoping-change-in-this>falsewarn-scoping-change-in-this> Inefficient use of += on a TextField.--> <warn-slow-text-field-addition>truewarn-slow-text-field-addition> Possible missing parentheses. --> <warn-unlikely-function-value>truewarn-unlikely-function-value> Possible usage of the ActionScript 2.0 XML class. --> <warn-xml-class-has-changed>falsewarn-xml-class-has-changed> compiler> compute-digest: writes a digest to the catalog.xml of a library. Use this when the library will be used as a cross-domain rsl.--> compute-digest usage:boolean--> remove-unused-rsls: remove RSLs that are not being used by the application--> <remove-unused-rsls>trueremove-unused-rsls> A list of runtime shared library URLs to be loaded before applications start. --> not set --> stringstring--> runtime-shared-library-path: specifies a SWC or directory to link against and an RSL URL to load with optional failover URLs --> Framework SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/framework.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/framework_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>framework_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> TextLayout SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/textLayout.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/tlf/2.0.0.232/textLayout_2.0.0.232.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>textLayout_2.0.0.232.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> Spark SWC--> <runtime-shared-library-path> <path-element>${flexlib}/libs/spark.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/spark_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>spark_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> Sparkskins SWC--> <runtime-shared-library-path> <path-element>${flexlib}/libs/sparkskins.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/sparkskins_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>sparkskins_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> RPC SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/rpc.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/rpc_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>rpc_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> Charts SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/charts.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/charts_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>charts_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> Spark_dmv SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/spark_dmv.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/spark_dmv_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>spark_dmv_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> OSMF SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/osmf.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/osmf_1.0.0.16316.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>osmf_1.0.0.16316.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> MX SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/mx/mx.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/mx_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>mx_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> Advancedgrids SWC --> <runtime-shared-library-path> <path-element>${flexlib}/libs/advancedgrids.swcpath-element> <rsl-url>http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/advancedgrids_4.6.0.23201.swzrsl-url> <policy-file-url>http://fpdownload.adobe.com/pub/swz/crossdomain.xmlpolicy-file-url> <rsl-url>advancedgrids_4.6.0.23201.swzrsl-url> <policy-file-url>policy-file-url> runtime-shared-library-path> static-link-runtime-shared-libraries: statically link the libraries specified by the -runtime-shared-libraries-path option.--> <static-link-runtime-shared-libraries>falsestatic-link-runtime-shared-libraries> target-player: specifies the version of the player the application is targeting. Features requiring a later version will not be compiled into the application. The minimum value supported is "9.0.0".--> target-player usage:version--> Enables SWFs to access the network. --> <use-network>trueuse-network> Metadata added to SWFs via the SWF Metadata tag. --> <metadata> <title>Adobe Flex 4 Applicationtitle> <description>http://www.adobe.com/products/flexdescription> <publisher>unknownpublisher> <creator>unknowncreator> <language>ENlanguage> metadata> licenses: specifies a list of product and serial number pairs. --> not set --> stringnumber-->flex-config>
备注:
1.其中${flexlib} 代表sdk的frameworks目录。
2.由于我的项目是Halo主题,所以设置<filename>${flexlib}/themes/Halo/halo.swcfilename>指定主题,
如果是spark主题,则:<filename>${flexlib}/themes/Spark/spark.cssfilename>。
最后:编写编译批处理
假定工程的application文件位于D:/project/src/test.mxml,依赖swc文件位于D:/project/src/lib目录,输出目录为D:/output
那么:建立批处理文件bulid.bat
@echo off cls set appPath=D:/project/
set outPath=D:/output
mxmlc -load-config flex-config.xml %appPath%/test.mxml -library-path+=%appPath%/lib -output %outPath%/test.swf