tags:

views:

1518

answers:

4

I have a flex project and if I build a release version of the application using flash builder with RSLs on my swf is 115k. If however I build the same application using ant the swf is 342k. Without RSLs the swf is 520k.

How do I get the swf to be as small as the one built by FlashBuilder?

Here is my ant file I have another task that copies the rsls.

<project name="EUI Client Application" default="compileClientApp">

<target name="compileClientApp" depends="compileClientBundles">
 <mxmlc 
  file="${CLIENT_PROJECT.dir}/src/${CLIENT_PROJECT.app}.mxml" 
  output="${DEPLOY.dir}/${CLIENT_PROJECT.app}.swf" 
  keep-generated-actionscript="false" 
  actionscript-file-encoding="UTF-8" 
  incremental="false"
  >

  <runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
   <url rsl-url="flex4_4.0.0.7791.swf"/>
   <url rsl-url="framework_4.0.0.7791.swf"/>
   <url rsl-url="framework_textLayout_4.0.0.7791.swf"/>
   <url rsl-url="rpc_4.0.0.7791.swf"/>
   <url rsl-url="textLayout_451.swf"/>
  </runtime-shared-library-path>

  <source-path path-element="${CLIENT_PROJECT.dir}/src" />

  <compiler.library-path dir="${LIBS.dir}" append="true">
   <include name="*.swc" />
  </compiler.library-path>
  <compiler.library-path dir="${DEPLOY_BIN.dir}" append="true">
   <include name="*.swc" />
  </compiler.library-path>

 </mxmlc>
</target>

<target name="generateWrapper">
 <html-wrapper 
  title="${CLIENT_APP_TITLE}" 
  file="${CLIENT_PROJECT.app}.html" 
  height="100%" width="100%" 
  bgcolor="white" application="app" 
  swf="${CLIENT_PROJECT.app}" 
  version-major="10" version-minor="0" version-revision="0" 
  history="true" output="${DEPLOY.dir}" />
</target>

<target name="compileClientBundles">
 <compileBundle bundleName="Modules" source="${CORE_PROJECT.dir}/locale" />
</target>

A: 

You'll probably need to specify the paths to the external libs using the -external-library-path option.

See the docs for more info.

To use RSLs when compiling your application, you use the following application compiler options:

* runtime-shared-libraries Provides the run-time location of the shared library.
* external-library-path|externs|load-externs Provides the compile-time location of the libraries. The compiler requires this for dynamic linking.

Use the runtime-shared-libraries option to specify the location of the SWF file that the application loads as an RSL at run time. You specify the location of the SWF file relative to the deployment location of the application. For example, if you store the library.swf file in the web_root/libraries directory on the web server, and the application in the web root, you specify libraries/library.swf.

You can specify one or more libraries with this option. If you specify more than one library, separate each library with a comma.

Use the external-library-path option to specify the location of the library's SWC file or open directory that the application references at compile time. The compiler provides compile-time link checking by using the library specified by this option. You can also use the externs or load-externs options to specify individual classes or an XML file that defines the contents of the library.

The following command-line example compiles the MyApp application that uses two libraries:

mxmlc -runtime-shared-libraries= ../libraries/CustomCellRenderer/library.swf, ../libraries/CustomDataGrid/library.swf -external-library-path=../libraries/CustomCellRenderer, ../libraries/CustomDataGrid MyApp.mxml

The order of the libraries is significant because the base classes must be loaded before the classes that use them.

You can also use a configuration file, as the following example shows:

../libraries/CustomCellRenderer ../libraries/CustomDataGrid ../libs/playerglobal.swc ../libraries/CustomCellRenderer/library.swf ../libraries/CustomDataGrid/library.swf

The runtime-shared-libraries option is the relative location of the library.swf files when the application has been deployed. The external-library-path option is the location of the SWC file or open directory at compile time. Because of this, you must know the deployment locations of the libraries relative to the application when you compile it. You do not have to know the deployment structure when you create the library, because you use the compc command-line compiler to create a SWC file.

Christophe Herreman
A: 

Try separating your RSLs into their own arguments. Here's what how I have it on my build:

<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/framework.swc">
 <url rsl-url="${rsl.url}/framework_3.2.0.3958.swz" />
 <url rsl-url="${rsl.url}/framework_3.2.0.3958.swf" />
</runtime-shared-library-path>

<runtime-shared-library-path path-element="${FLEX_HOME}/frameworks/libs/datavisualization.swc">
 <url rsl-url="${rsl.url}/datavisualization_3.2.0.3958.swz" />
 <url rsl-url="${rsl.url}/datavisualization_3.2.0.3958.swf" />
</runtime-shared-library-path>
DyreSchlock
+2  A: 

Thanks for the replies guys but it wasn't either of those.

turns out all I needed to do was to remove the runtime-shared-library-path stuff as this is already in the flex-config.xml file. I also had to change the static-link-runtime-shared-libraries to false (so it's dynamic).

I've copied the flex-config.xml file into my build directory and use that so I can safely make changes.

This is with Flex 4 BTW - nto sure if I made that very clear.

my ant file now looks like this:

<project name="EUI Client Application" default="compileClientApp">

<target name="compileClientApp" depends="compileClientBundles">
 <mxmlc 
  file="${CLIENT_PROJECT.dir}/src/${CLIENT_PROJECT.app}.mxml" 
  output="${DEPLOY.dir}/${CLIENT_PROJECT.app}.swf" 
  keep-generated-actionscript="false" 
  actionscript-file-encoding="UTF-8" 
  optimize="true" incremental="false"
  link-report="${DEPLOY_BIN.dir}/app_link_report.xml"
  >

  <load-config filename="${basedir}/flex-config.xml" />

  <define name="CONFIG::stub" value="false" />
  <define name="CONFIG::release" value="true" />

  <source-path path-element="${CLIENT_PROJECT.dir}/src" />

  <compiler.library-path dir="${LIBS.dir}" append="true">
   <include name="*.swc" />
  </compiler.library-path>
  <compiler.library-path dir="${DEPLOY_BIN.dir}" append="true">
   <include name="*.swc" />
  </compiler.library-path>
 </mxmlc>
</target>

<target name="generateWrapper">
 <html-wrapper 
  title="${CLIENT_APP_TITLE}" 
  file="${CLIENT_PROJECT.app}.html" 
  height="100%" width="100%" 
  bgcolor="white" application="app" 
  swf="${CLIENT_PROJECT.app}" 
  version-major="10" version-minor="0" version-revision="0" 
  history="true" output="${DEPLOY.dir}" />
</target>

<target name="compileClientBundles">
 <compileBundle bundleName="Modules" source="${CORE_PROJECT.dir}/locale" />
</target>

Roaders
A: 

Using RSL, remember to set use-network parameter to true, otherwise the compiled swf will complain security error (can't load RSL) when run in different location.

Gnought