Does anyone know of a way to use the mxmlc Flex Ant task with a user-defined list of source or library paths?
The user should be able to define an arbitrary list of source and/or library (.swc) paths in an Ant properties file and the build file can use these values in the mxmlc task.
Are there any tricks (maybe use filtering/string replacing) to get this working?
Don't know if this helps, but you can include an external XML in your Ant build file:
<?xml version="1.0" ?>
<project name="test" default="test" basedir=".">
<target name="setup">
...
</target>
<import file="./common.xml" />
</project>
I ran across your question, looking for a way to define the library (and source path) definitions in external files. Looping through a list of defined properties seems somewhat problematic to me, since you would possibly have to define a list of library paths as well as sub-lists of files in each defined path in the list.
Seems that including external files defining the library and various source paths might be a better and just as extensible way to go.
They way I do it is list my source paths, library paths etc. in an external mxmlc configuration file (e.g. flex-config.xml), my more-or-less universal build.xml file just does
<mxmlc file="${app.mainClass}" output="${swf}">
<load-config filename="${air.sdk.config}" />
<load-config filename="${app.config}" />
</mxmlc>
Where air.sdk.config points to the SDK's default config xml and app.config is the app's custom config xml.
I don't know if it is possible to do it from a properties file.
You can use this in your Ant script:
<source-path>
<source-path path-element="my/src/dir" />
</source-path>
<library-path dir="my/libs/dir" append="true">
<include name="*.swc" />
</library-path>
Or maybe develop some Ant module to simulate this from your properties file.
I can't understand why you want to make your properties file dynamic, it is the role of your build.xml normally, but hey :)
Related
This should be easy, but I can't find it. I want my .html and .swf files to be named something differently than the project name. Project name is foo, I want the outputs to be bar.html and bar.swf. Thanks.
Flextras was on the right track. You can't change the output filename (even using the "-output" compiler param) if you're compiling in Flash Builder. Not sure why.
The solution that has worked for me has been to use a bit of indirection:
use mxmlc to compile to ApplicationClass.swf
command line copy ApplicationClass.swf to YourCustomSwf.swf
command line run YourCustomSwf.swf
You can do this with either a simple (platform-dependent) build script, or with Flex Ant Tasks. I highly recommend the latter; it's easy to setup, integrates well with Flash Builder, and (as a mostly platform-independent solution) will work in a multi-team multi-OS environment. Here are the above steps as ant tasks that will perform the magic for you:
<project name="sample-build" default="run-your-swf">
<property file="${basedir}/your.properties.file"/>
<target name="compile-your-app">
<mxmlc file="${SOURCE_DIR}/ApplicationFile.mxml" compiler.debug="${IS_DEBUG}" incremental="true" failonerror="true">
<load-config filename="${DEFAULT_FLEX_CONFIG}"/>
<define name="CONFIG::DEBUG" value="${IS_DEBUG}"/>
<define name="CONFIG::FLASH_AUTHORING" value="${IS_FLASH_AUTHORING}"/>
<define name="CONFIG::IS_RELEASE" value="${IS_RELEASE}"/>
</mxmlc>
</target>
<target name="rename-your-swf" depends="compile-your-app">
<copy file="${OUTPUT_DIR}/feed/FeedComponent.swf" tofile="${OUTPUT_DIR}/YourNewSexyFilename.swf"/>
</target>
<target name="run-your-swf" depends="rename-your-swf">
<exec executable="${STANDALONE_FLASH_DEBUG_PLAYER}">
<arg line="${OUTPUT_DIR}/YourNewSexyFilename.swf"/>
</exec>
</target>
</project>
you need only define all ${VARIABLES} I've listed in "your.properties.file", like so:
FLASH_PLAYER_DEBUG=/Applications/Adobe Flash CS5/Players/Debug/Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger
IS_DEBUG=true
(et cetera)
And anyway - what's in a name? A program by any other name, would be as awesome... B-)
According to the Adobe asdocs, Flex framework files are supposed to be able to be loaded at runtime. These localized framework files, the ones that exist at (on windows) C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.0\frameworks\locale, are responsible for items such as button text on Alert Dialogs, and a host of other controls. My expectation is that once these framework files are loaded I would see these resources available in my Flex app.
I've set up my project as follows:
MyProject
-src
-Flex4.5
-Referenced Libraries
-bin-debug
-bin-release
-libs
-locale (I've copied all of the directories(da_DK,en_US,es_ES,etc) of framework files for the locales I want to support inside of this dir)
Now the asdocs state that in order to do this, you have to set the compiler settings to read
-locale=en_US,da_DK,de_DE,es_ES,fi_FI,fr_FR,it_IT,ja_JP,ko_KR,nb_NO,nl_NL,pt_BR,ru_RU,sv_SE,zh_CN,zh_TW -allow-source-path-overlap=true -source-path=locale/{locale}
which I have done.
My Build Path Libraries for Flex 4.5 - C:Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.0 are set to be Runtime Shared library (of note, the {locale} subfolder says "Merged into code")
But when I change the language in the browser, I'm not seeing any of the framework resources.
Also, when I build my project, I don't see any indication of the locale-oriented resource files in the bin-release. Since we only deploy the contents of the bin-release folder (and not the entire project), how is this supposed to work?
I am also seeing .swz files in my bin-release (and I know these arent the localized framework resources).
Does anyone have any experience with Runtime Framework Localization?? What am I doing wrong? My expectation is that once I build my project (with the framework resources externalized) that the app would be able to load those resources, but this isn't happening and I am not interested in compiling a different version of my app for all of the locales I support.
Thanks in advance
I use the following ANT task which works for me:
<mxmlc file="${build.dir.src}/${mxml.file}" keep-generated-actionscript="false" output="${build.dir.stage}/${project.app.name}.swf"
actionscript-file-encoding="UTF-8" incremental="false" context-root="${project.app.name}" optimize="${app.optimize}"
debug="${app.debug}" configname="air" locale="en_US,ja_JP,fr_FR">
<jvmarg value="-Xmx1024m" />
<jvmarg value="-Xms512m" />
<compiler.theme append="true" file="${FLEX_HOME}/frameworks/projects/spark/MXFTEText.css" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<source-path path-element="${build.dir.locale.src}/{locale}" />
<library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/libs/air" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/locale" append="true">
<include name="{locale}" />
</library-path>
<library-path dir="${build.dir.lib}" append="true">
<include name="*.swc" />
</library-path>
Add the following tag to the classes that use resources and read the strings in the way:
[ResourceBundle('application')]
// set up the locale chain
ResourceManager.getInstance().localeChain = [ 'en_US', 'ja_JP', 'fr_FR' ];
// load resources
ResourceManager.getInstance().getString('application', 'some.string.code');
An observation: One does not need to copy the framework files into one's project folder. They will be picked up the compiler when compiling.
Let me know if it works, else we can debug more!
Our Flash web-based applications play lots of audio for narration and sound-effects. Some of our customers have firewall rules that block downloading of MP3 and other audio files. So, we need to wrap those MP3 files in SWFs. In the past, I've written JSFL scripts that automate the Flash IDE and walk through a complicated, fragile set of steps to embed MP3 files into FLAs and then publish those to SWFs. Now, Flex SDK provides the mxmlc compiler. I've mixed ANT into our workflow, and command-line and automated builds have been a joy. So, I want to make transcoding or wrapping of MP3s part of our build process. I've found Embedding Asset at Compile time in Pure AS3, but this will require that I write a script to generate a wrapper class AS file. Is there a cleaner way to wrap or transcode MP3 files into SWFs? I suppose I'm hoping there is a method for passing the mp3 directly to mxmlc and outputting a swf, but any recommendation better than generating actionscript wrapper classes would be greatly appreciated.
Since you are using MXMLC and Ant already, you should consider adding another bit of code to your Ant build script to build your MP3s into a library SWC. You can then build that SWC into the executable SWF (I've left that simple step out of my example below).
Since all you'll need is Ant, doing it this way is no more difficult than how you're already building your SWF. The only real "gotcha" is that you need to embed your files using an MXMLC/SWC-friendly absolute path (e.g. "/myAssets/myasset.mp3") in your code.
Because it has access to Project metadata, Flash Builder "knows" where the root of your project is, allowing it to use relative embed paths. MXMLC doesn't have any of this info. You therefore need to make sure that the embeds are declared to match the absolute location of how the files are stored in the SWC. If you do this, both Flash Builder and MXMLC/Ant will be able to understand your embeds. That way, everybody's happy.
To help you along, below is an example Ant script for building an asset SWC. Here are the key steps, in a nutshell:
Build up a String containing the locations of the files to be included, one by one
Compile those assets into a SWC using MXMLC and a monster-sized set of command-line arguments
The following script will package jpgs, pngs, svgs, ttfs, xml files, properties files and MP3s into a file called "assets.swc". You'll need to include flexTasks.jar (for obvious reasons) and ant-contrib.jar in the appropriate relative locations and set a FLEX_HOME environment variable.
<?xml version="1.0" encoding="utf-8"?>
<project name="My App Builder"
basedir="."
default="buildSWC"
xmlns:antcontrib="antlib:net.sf.antcontrib">
<taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasks.jar"/>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/libs/ant-contrib-1.0b3.jar"/>
<property environment="env"/>
<property name="FLEX_HOME" value="${env.FLEX_HOME}"/>
<property name="ASSETS_FILE" value="assets.swc"/>
<property name="SRC_DIR" value="./src"/>
<!-- Prepare folders for SWC compilation -->
<target name="buildSWC">
<echo message=""/>
<echo message="*****************************************************"/>
<echo message="* ${ASSETS_FILE}"/>
<echo message="*****************************************************"/>
<echo message="...basedir: ${basedir}"/>
<!-- Build a swc from statically-included assets (images, mp3s, xml files, properties files) -->
<fileset id="assets.flex" dir="src" includes="**/*.jpg,**/*.png,**/*.mp3,**/*.css,**/*.svg,**/*.swf,**/*.TTF,**/*.jpeg,**/*.xml,**/*.properties"/>
<pathconvert pathsep=" " property="assets.flex.output" refid="assets.flex" dirsep="/">
<map from="${basedir}/src/" to=""/>
</pathconvert>
<echo message="...Resources being considered..."/>
<var name="filelist" value=""/>
<var name="prefixfilelist" value="-include-file"/>
<for list="${assets.flex.output}" delimiter=" " param="asset">
<sequential>
<echo>Asset: #{asset}</echo>
<propertyregex property="prop"
input="${asset}"
regexp="(.*)${SRC_DIR}/(.*)"
select="\2"
casesensitive="false"
defaultvalue="./src/"/>
<echo>Prop: ${prop}</echo>
<var name="filelist_tmp" value="${filelist}"/>
<var name="filelist" unset="true"/>
<var name="filelist"
value="${filelist_tmp} ${prefixfilelist} ./#{asset} ${prop}#{asset}"/>
<var name="prop" unset="true"/>
</sequential>
</for>
<echo message="-output ${ASSETS_FILE} ${filelist}"/>
<!-- Windows Compile -->
<exec executable="${FLEX_HOME}/bin/compc.exe"
failonerror="true"
osfamily="winnt">
<arg line="-output ./libs/assets.swc ${filelist}"/>
</exec>
<!-- Unix/Linux Compile -->
<exec executable="${FLEX_HOME}/bin/compc"
failonerror="true"
osfamily="unix">
<arg line="-output ./libs/assets.swc ${filelist}"/>
</exec>
</target>
</project>
We use this approach (which I pieced together from bits and pieces I found on the internet -- I'd gladly give credit if I remembered where) to build a large, module-based project and its embedded images and fonts. There is no reason to think that it wouldn't work for audio files.
Good luck,
Taylor
P.S. There might be some leftover/useless lines of code in there. Also, I'm not an Ant expert, so to any "Ant guys" out there: take it easy on me if I broke any best practices ;)
I would like to build a flex library project automatically instead of the current process, which involves one of our developers compiling it on his machine and then us checking in the resulting .swc file. It's gross.
I am coming at this from the perspective of a java developer, so I'm having a hard time getting the hang of the compilation tools provided in the Flex Builder 3 application, but here's what I already have:
I have created an ant file that loads the ant task library correctly, and can therefore execute <mxmlc/> and <compc/> tasks.
I have located the source code that I need to build, and know what sort of .swc I want to end up with.
What I want is an ant script that will do the equivalent of these steps:
We build all sources (actionscript and MXML) and assets in the project into an swc file.
The library.swf file is extracted and optimized
So far I have this:
<target name="compile-component" depends="init">
<compc output="${DEPLOY_DIR}/${SWC_NAME}.swc">
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${SRC_DIR}"/>
</compc>
</target>
However, it's not including any content:
[compc] Loading configuration file /Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/flex-config.xml
[compc] Adobe Compc (Flex Component Compiler)
[compc] Version 3.2.0 build 3958
[compc] Copyright (c) 2004-2007 Adobe Systems, Inc. All rights reserved.
[compc]
[compc] Error: nothing was specified to be included in the library
[compc]
[compc] Use 'compc -help' for information about using the command line.
It looks like I need to enumerate every class that I want to include in the library, which is... ludicrous. There must be a better way. How do I do this?
You can do the following... it takes all the files from the source path and converts it to a format that the compc task can then use.
<fileset id="project.test.dir.fileset" dir="${project.test.dir}">
<include name="**/*.as" />
<include name="**/*.mxml" />
</fileset>
<property name="project.test.dir.fileset" refid="project.test.dir.fileset" />
<!-- Convert the test files into a compiler friendly format. -->
<pathconvert property="project.test.dir.path" pathsep=" " refid="project.test.dir.fileset">
<compositemapper>
<chainedmapper>
<globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
<mapper type="package" from="*.as" to="*" />
</chainedmapper>
<chainedmapper>
<globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
<mapper type="package" from="*.mxml" to="*" />
</chainedmapper>
</compositemapper>
</pathconvert>
<compc headless-server="true" default-frame-rate="${flex.default-frame-rate}" debug="${flex.compiler.debug.mode}" output="${build.swc.dir}/${test.component.name}.swc" include-classes="${project.test.dir.path}" directory="false">
<source-path path-element="${project.test.dir}" />
&dependencies;
</compc>
We use it to produce swcs for testing purposes.
Lucky for you I JUST solved this problem and was looking for the answer to another problem!
<compc output="${basedir}/mySwc.swc" locale="en_US">
<source-path path-element="${basedir}/src/main/flex"/>
<include-sources dir="${basedir}/src/main/flex" includes="*" />
<load-config filename="${basedir}/fb3config.xml" />
</compc>
The source-path is necessary to tell it what to look at when trying to resolve various references. The include-sources tells it which sources to include (obviously in this case all of them). The load-config is just the -dump-config output from Flex Builder.
Hope this helps!!
You can use Maven. It's a configuration management tool rather than just a build tool. It does rely on your project having a manifest file.
I've created an AIR application, but it uses an external SWF for extra functionality. I want that SWF to be included in the install, but currently it's not. Is there anyway I can get FlexBuilder or any other tool to include this extra file in the installer? I've tried manually adding the file (as a .air file is just a zip file in disguise), but there must be hash checks inside the file.
If you place the SWF file in your application's src directory it will give you the option to include in the installer (previously I tried putting it in the application's root folder).
If you are working in Flash, go to File>Adobe AIR 2.0 Settings. At the bottom of the dialgoue box is a list of included files. Add your SWF to that list.
What if you wanted to add a text file instead to the installer using Flex Builder? I tried to add it using the export release build wizard, but I don't see the text file generated in the application directory...any ideas?
I would add a custom builder, under project -> properties -> builders
I use something like the following for one of my projects that I want to package some mxml and as files with so that the compiler doesn't try to compile them on export. Save the xml below as something like copy_files.xml and add a new Ant Builder to your project. Under the targets tab of the builder I have mine set to run the copy-files target on every clean.
<?xml version="1.0" encoding="UTF-8"?>
<project name="SampleProject">
<target name="copy-files" description="Copy Source Files">
<copy todir="bin-debug/sources">
<fileset dir="sources" >
<include name="**/*.*" />
</fileset>
</copy>
<copy todir="bin-release/sources">
<fileset dir="sources" >
<include name="**/*.*" />
</fileset>
</copy>
</target>
</project>