Flash Builder (Flex) ANT build and Debug - apache-flex

I'm trying to use ANT with Flash Builder 4 to compile and debug.
The compiling is the easy part but having trouble to get the debugger to work.
I want to use ANT to Debug SWF file inside Flash Builder, so that breakpoints, console traces and everything works as it should.
My script so far. Builds The *.as to *.swf and moves from bin-debug to deploy folder. How can I start a Flash Builder Debugger for the created SWF?
<target name="Compile level 1">
<antcall target="compile flex file">
<param name="file" value="GameOffice"/>
</antcall>
<antcall target="open player">
<param name="file" value="GameOffice.swf"/>
</antcall>
</target>
<target name="compile flex file">
<mxmlc file="${SRC_DIR}/${file}.as" output="${BUILD_DIR}/${file}.swf"
actionscript-file-encoding="UTF-8"
keep-generated-actionscript="true"
incremental="true"
static-link-runtime-shared-libraries="true"
show-actionscript-warnings="true"
failonerror="true"
debug="true"
optimize="false">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.include-libraries dir="${basedir}/libs" append="true">
<include name="HelloThereLibGames.swc" />
<include name="HelloThereLibStructure.swc" />
<include name="HelloThereLibUtils.swc" />
</compiler.include-libraries>
<metadata description="Hello There Production">
<contributor name="Fredrick Bäcker" />
</metadata>
</mxmlc>
<copy todir="${DEPLOY_DIR}" file="${BUILD_DIR}/${file}.swf"/>
</target>

I did a 1 try one hit on google: http://blogs.4point.com/armaghan.chaudhary/2009/04/remote-debugging-using-flex-builder-ide.html
I do not get why you would want to build with ant inside flashbuilder. Seems like crossing the stream for water?
IMHO automated build scripts belong in CI environments like hudson. I consider it doing myself a favor, letting my development environment handle the fuzz of local builds and debugging.
Anyways, best of luck

Assuming you are working off a local web server, you can simply open the debug socket in Flash Builder by setting your debug launch config to a blank html page (eg. about:blank) and then opening your browser to your localhost (or whatever url you've set up).
In this case you would run the build with ant, hit debug to open the socket, then switch over to your web browser and load localhost.

I realise this answer is probably a little late, but better late than never!
Is pretty simple really when you know how. I did a blog entry on it a while back that should show you how:
http://blog.tiltdigital.com/flex/running-flash-builder-4-in-debug-mode-from-apache-ant/
Basically you just need to add an Ant Builder to Flash Builder 'Builders' properties in your project properties. You can then use that to compile/debug using your build script as you'd normally do using the Flash Builder Compiler/Debugger.

Related

specify ouput file name flash builder 4

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-)

Flex 4.5.1 runtime ReferenceError: Error #1065: Variable ... is not defined

Ok, I need some help on this one. I upgraded from Flash Builder 4 to Flash Builder 4.5 and have switched my project to the 4.5.1 sdk. I use an ant script to build my project, so I modified it to use the appropriate flexTasks.jar, mxmlc, etc...
Now, if I start out with a blank bin-debug folder, then build and run the app everything works fine. However, if I then make a code change and build (without deleting the bin-debug) then run the app I get a runtime error:
ReferenceError: Error #1065: Variable ... is not defined.
at flash.display::MovieClip/nextFrame()
at mx.managers::SystemManager/deferredNextFrame()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\SystemManager.as:284]
at mx.managers::SystemManager/preloader_preloaderDocFrameReadyHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\SystemManager.as:2633]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:515]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
Again, if I delete the bin-debug folder and compile again it runs with no problems.
The variable it complains about is always a Class variable that points to an image file used as an icon. The code I use to create the var:
[Embed(source="/assets/icons/close-32x32.png")]
public var closeIcon:Class;
The file exists, and I verified that when it gives that error the file is in the bin-debug/assets/icons folder and the src/assets/icons/ folder.
After the error is thrown, if I hit the continue button in Flash Builder it then throws the same error again on the next Class variable pointing to an image file.
Any ideas? The delete/recompile takes several minutes, so obviously this is driving me mad.
Edit: Ant task that compiles in debug mode:
<target name="compile-debug">
<echo>Compile MXML</echo>
<mxmlc
file="${SRC_DIR}/${MAIN_SOURCE_FILE}"
debug="true"
optimize="false"
output="${DEBUG_DIR}/${APP_ROOT_FILE}"
append="true"
actionscript-file-encoding="UTF-8"
keep-generated-actionscript="false"
link-report="MyReport.xml"
maxmemory="2048m"
incremental="true">
<!-- Get default compiler options. -->
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>
<!-- List of path elements that form the roots of ActionScript class hierarchies. -->
<source-path path-element="${FLEX_HOME}/frameworks"/>
<!-- Include Themes -->
<!-- NOTE: Spark theme required -->
<theme dir="${FLEX_HOME}/frameworks/themes/Spark/">
<include name="spark.css" />
</theme>
<theme dir="${FLEX_HOME}/samples/themes/spark_graphite/">
<include name="spark_graphite.css" />
</theme>
<!-- List of SWC files or directories that contain SWC files. -->
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
<include name="../bundles/{locale}" />
</compiler.library-path>
<!-- uncomment if you have external libs (swc files) -->
<library-path dir="${LIB_DIR}/riaspace/" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${LIB_DIR}/AlivePDF/" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${LIB_DIR}/coltware/" append="true">
<include name="*.swc" />
</library-path>
</mxmlc>
</target>
Where FLEX_HOME = < path to flash builder >/sdks/4.5.1
The answer is buried in the middle of Maxim's post that he referenced in a comment above:
--> Try turning off incremental compilation.
I had the same issue here with a simple mimeType='application/octet-stream' embed, and when reading Maxim's text this jumped out because I'd recently changed my custom build tools to use inremental compilation: "Embed sometimes fails during incremental compilation"
The result of this failure is that the .swf contains something like this:
<DefineBinaryData id='1' length='1024' />
which looks like it's empty, instead of this (from the working file):
<DefineBitsLossless2 id='1' encoding='base64'>
(.. in my case, 1024 bytes of base64-encoded data)
</DefineBitsLossless2>
(This solved it for me, so a big thank-you to Maxim. I hope it solves it for you too.)
I had the same problem, so I "Clean"ed the project and then re ran. It worked.
I have Flash Builder 4.7 and am using sdk 4.5.1A.
I was using Flash Player debugger version 15 before Christmas of 2014 and everything was working. I had Firefox set up as the default browser. However, in 2015, Adobe has a new player so I upgraded to version 16 and that's when I got the same problem. After much struggle, I found that the problem had to do with the new version of Firefox Flash player debugger. I had to switch the default browser to Internet Explorer and installed the Internet Explorer Flash player debugger. Prior to debugging, I had to clean and update first. Then everything worked again!

Adobe Flex 4: Runtime Loading of Localized Framework Files

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!

Wrapping or Embedding and MP3 in a SWF using Flex's mxmlc compiler

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 ;)

Using the ASP Compiler in NAnt to build an ASP .Net MVC application

I am succesfully building ASP .Net applications in NAnt using the ASP Compiler, without a problem., as part of my Continuous Integration process.
However, if I try exactly the same process on an ASP .NET MVC application, the build fails in NAnt, but will compile succesfully in Visual Studio. The error message I get in NAnt is:
[HttpParseException]: Could not load type 'MyNamespace.Views.Home.Index'
which appears that it has a problem with the dots in the filenames, but I might be wrong.
Any suggestions are most welcome.
You shouldn't install ASP.NET MVC onto the build box. You should be referencing the System.Web.MVC, System.Web.Routing and System.Web.Abstractions DLLs from wherever you store your third-party references. We normally have a /lib folder for all references where we have those 3 DLLs (and many more) stored and a /src folder where all of our code lives. If you are referencing these DLLs this way, you no longer have to rely on the environment for those DLLs. This blog post explains this idea in more detail.
Installing the MVC bits on the build box should sort this out--it is either lacking the .dlls to know your Home.Index view descends from System.Web.Mvc.ViewPage or it doesn't have the right project template for the compiler to use.
The MVC app needs to be built as a project before using aspnet_compile. If your MVC project uses other class library projects, they also need to be compiled.
After running aspnet_compile, we then want to delete various files that should not be part of the deployed site.
This build file is located in the parent directory to my project MvcApplication.
<project default="build">
<property name="build.dir" value="${project::get-base-directory()}"/>
<property name="build.config" value="Release" />
<target name="build">
<exec program="${framework::get-framework-directory('net-3.5')}/msbuild.exe">
<arg value="/property:Configuration=${build.config}" />
<arg value="${build.dir}/MvcApplication/MvcApplication.csproj" />
</exec>
<delete dir="${build.dir}/PrecompiledWeb" includeemptydirs="true" failonerror="false"/>
<exec program="${framework::get-framework-directory('net-2.0')}/aspnet_compiler.exe">
<arg value="-v" />
<arg value="/" />
<arg value="-p" />
<arg value="MvcApplication/" />
<arg value="-f" />
<arg value="PrecompiledWeb" />
</exec>
<delete verbose="true" includeemptydirs="true" failonerror="false">
<fileset basedir="${build.dir}/PrecompiledWeb">
<include name="Controllers" />
<include name="Properties" />
<include name="obj/**" />
<include name="obj" />
<include name="*.csproj" />
<include name="*.csproj.user" />
</fileset>
</delete>
</target>
</project>
Not exactly an answer to your question but more a different tack that might solve what you wish to achieve.
I find studio to be more friendly that the asp compiler from the command line.
Could you not build it with devenv.exe through a NAnt command line task.
Best of luck,
Dan
On a project I was working on recently we build the ASP.NET MVC web app using this target:
<target name="CompileSite" depends="blah blah">
<exec program="${framework::get-framework-directory('net-2.0')}\aspnet_compiler.exe" commandline="-p "${SrcDir}\Website" -v / -d "${CompiledSiteOutputDir}" -fixednames" workingdir="${BaseDir}" />
</target>
so it is definitely possible. Our views were named something like ProjectName.Views.News.List etc.
Could you provide more details? Does the compiler say where it encounters the error (file, linenumber etc.)?
My best guess is that the ASP.Net mvc dll's are not installed on the build server. ASP.Net MVC is a separate download.

Resources