As these discussions illustrate it is not currently possible to do so. And though we are looking into some possible
solutions, they may not be implemented soon. So here I am to save the day and provide you with a viable workaround,
until we get the matter sorted out.

Use case

This solution is heavily based on mrhaki’s excellent article, but it is tailored specifically for the Flex
developer that needs to generate multiple outputs for different environments from a single project. I created this when
facing a real-world issue and the solution is being used in production right now, so it’s been tried and tested.

The specific situation I was facing was that I needed mock services and embedded mock data, in such a way that the
application could run in standalone mode (i.e. without a server) and give a realistic feel to the users testing the UI.
Of course in the production build I did not want to include all the additional classes and certainly not the embedded
data. So here’s how I created a “clean” production output and a heavyweight development output including the mocks.

A groovy configuration

Let’s start by stubbing out our config file for two different environments.

Good, that’s how mrhaki described it. Now lets add some properties that we can use in a GradleFx build. Note that I put
all the mock-related code and the resources (the data files) in a separate source tree (src/mock/), which allows me
to easily add/remove that part when needed.

config.groovy

12345678910111213141516171819202122232425262728293031

environments{dev{//I added the resources folder to the 'srcDirs' because the files had to be embeddedsrcDirs=['src/mock/actionscript','src/mock/resources']//fx-mocks is a library that helps with simulating data from services//fx-users-dev is a special build of the fx-users lib that also includes mock services and datadependencies.merged=['net.riastar.lib:fx-mocks:1.0-SNAPSHOT','net.riastar.lib:fx-users-dev:1.0-SNAPSHOT']//it's gonna run in standalone mode so we set a bigger default window size//mock services are injected, so they're never referenced explicitly;//that's why we have to add them through the 'includes' optionadditionalCompilerOptions=["-default-size=1024,600","-includes="+"net.riastar.myapp.service.impl.UserMockService,"+"net.riastar.myapp.service.impl.MyValueObjectMockService"]}production{//in production we don't use the mock classes and resources,//we don't use the mock library and we use the production build of the fx-users library.srcDirs=[]dependencies.merged=['com.trasysgroup.lib:fx-users:1.0-SNAPSHOT']additionalCompilerOptions=[]}}

Note that in production I mirrored every property that I declared in the dev block, if only to set its value to an
empty array. This is not strictly nesessary, but it will make the code in the build file a lot more readable later on.

Use it in a build script

So we’ve configured our two environments. Next I will show you how to modify the Gradle(Fx) build script to leverage it.
As in mrhaki’s post, this script reads the custom env property from the issued command and processes the config file
accordingly. Hence you’ll be able to initiate the build of a specific build like so:

1

$ gradle clean build -Penv=production

build.gradle

1234567891011121314151617181920212223242526

buildscript{repositories.mavenCentral()dependencies.classpath'org.gradlefx:gradlefx:0.6.4'}applyplugin:'gradlefx'type='swf'//'development' build by default if the 'env' argument wasn't set//I'm not gonna explain this code: read mrhaki's postdefenvironment=hasProperty('env')?env:'development'ext.config=newConfigSlurper(environment).parse(file('config.groovy').toURL())//add our custom srcDirs to the default onessrcDirs+=config.srcDirsdependencies{//add our custom libraries; swiftsuspenders will be used both in production and developmentmerged'org.swiftsuspenders:swiftsuspenders:2.0.0-rc1',config.dependencies.mergedflexSDK'org.apache:apache-flex-sdk:4.9.1'}//add our custom compiler optionsadditionalCompilerOptions=config.additionalCompilerOptions

See why we declared empty arrays in the production block? It would’ve required some conditional logic if we hadn’t,
leaving the result much less elegant and readable. Especially the merged dependency would’ve been butt-ugly; believe
me, I tried.

Conclusion

Well that’s about it. It’s not extremely complicated and it’s fairly elegant. I know it’s not exactly the Gradle way,
but it gets the job done without too many compromises. Hope this helps someone.

It was bound to happen at some point: I got hacked. Don’t know when, don’t know why. I only know that someone broke
into my server, replaced the index page with a nice picture of the Koran and some Engrish proze praising the love of
God. My islamist visitor was kind enough to leave the rest of my content untouched - for all I know, that is.

Now how could this happen?

Well, since I can find the time to write on this blog - say - once a year, how often do you think I applied security
updates to my WordPress blog?

Right!

So, because a Wordpress engine was overkill for my requirements anyway, not to mention slooooooow, I went CMS hunting
and found the perfect solution with OctoPress. This is a perfectly geeky CMS that generates static html pages.
You write your posts in MarkDown - oh yeah, pure text, no WYSIWYG involved; then you execute the generate
command on the command line; your site is generated and ready to deploy.

I had a pretty hard time getting it to run on my Windows box: it’s written in Ruby which doesn’t like Windows very
much. And I had no luck at all installing it under Cygwin, so for the time being I’m stuck in a DOS shell to
issue my commands.

New server

By chance I came across PagodaBox just about the same day. It is to Php what Heroku is to Ruby: a scalable
hosting service in the cloud. Fortunately they had a free offering that - though limited - allowed me to play
around. And I really love it, mostly for its Git deployment interface.

The result is that I ended up with a workflow to write a new post and deploy it to my PagodaBox instance, that
goes like this:

Today I’ve taken my first steps in the open-source world: I became a committer to the GradleFx project.

What project say you?

GradleFx is an automated build tool for building Flex and ActionScript applications. It’s a plugin for Gradle,
which is an alternative to the ubiquitous Maven. Actually calling it an alternative would not be doing it justice:
it’s Maven, Ivy and ANT mixed up and put on steroids.

Until GradleFx came to the scene, us poor Flex developers only had FlexMojos (a Maven plugin with the
same goal) at their disposal. And truth be said: it has some very annoying bugs. So when I discovered GradleFx I
was delighted.

When I first gave GradleFx a try, I got a few builds up and running in no time. Unfortunately, I soon found out
that GradleFx - being a fairly young project - was missing a few pieces. But since Gradle was designed to
be an easily extensible framework, I worked my way around those shortcomings with some custom tasks.

First steps

I soon discovered that GradleFx’ codebase was fairly transparent (as opposed to FlexMojos’). So I forked the
project on GitHub and I started adding some minor features. Yennick, one of the founders and currently the
only active committer, seemed to like my ideas. He merged them into the codebase rather quickly, encouraged me to keep
on contributing and before I knew what happened, I became part of the ‘team’.

I’ve lost count on how many times I’ve needed this in RIA development with Flex or ActionScript: the possibility to
quickly copy property values from one class instance to another. The two most important uses I can think of right now
are these:

You send a value object (VO) to the server. It comes back with a bunch of additional data. So far so good. But what
you get back is another instance than the one you’ve just sent up the wire. Since the original instance may already be
referenced somewhere in the application we do not want to simply replace it. We want the original instance filled with
the new property values.

You show the user a form with which he can edit a VO. After he’s changed some values he can either commit his changes
(‘OK’ button) or discard them (‘cancel’ button). In this scenario you’ll usually keep a copy of the original VO
somewhere handy because you want to be able to restore it when needed. Now the story is the same as the previous one:
we want to restore the values of the original instance, not replace it entirely.

So I finally made this convenience method that uses describeType() for introspection as an addition to my
ObjectUtil class:

vareditableItem:MyClass=ObjectUtil.clone(originalItem);//the user edits editableItem//if he cancels we just discard this instance//if he commits his changes we copy the new valuesObjectUtil.copyProperties(editableItem,originalItem);

Some time ago I created Protection. It was a library intended to help me write more readable ActionScript code without
breaking out of the paradigms that were set out by Adobe. You can find a more thorough explanation and motivation in
an article I wrote earlier this year. I have been using it a lot now and as much as I like the basic idea, I came
to realise that I had made a few wrong decisions. Most importantly:

overcomplicated nomenclature: in a silly attempt at originality I used military metaphors throughout the library
(Sentries, Captains, Spies, etc.). These names make the code actually less transparent to someone who doesn’t know
where they originated (i.e. anyone but me). This is in clear violation with my original intent: more readable code.

too many optional arguments: a lot of different configuration was passed through one method with a bunch of
optional arguments. Again, this would not be transparent to someone who read such code for the first time.

used inheritance (instead of composition) to add the functionality to custom components

string-based conditionals: "r:propertyA", "f:propertyB" to pass ‘propertyA’ to the result handler and ‘propertyB’
to the failure handler? Not so pretty.

Enter Gigs (a.k.a RIAstar events)

So I decided to rethink the whole thing. To start with, the library name will remain my only attempt at originality.
But let’s get down to the real stuff. This is how you use Gigs for tracking native Events:

You can also join a ‘gigs.properties’ file to the application in which you can associate default event types to specific
classes. For instance 95% of the time on Buttons we listen for CLICK events. So we register a default for that:

1

spark.components.supportClasses.ButtonBase=click

And then we can write the following to do the same thing as before:

1234

follow(submitButton).handle(submit);//we can still explicitely listen for//another event than the registered defaultfollow(submitButton).by(MouseEvent.MOUSE_DOWN).handle(startDrag);

Passing property values

The ‘handle’ method takes one additional …rest argument to which you can pass all the event properties you want pass
to the result handler. For example (I’ve registered the ListBase class with the IndexChangeEvent.CHANGE event type):

CFInvoke assumes that the url of the service and its endpoint are the same. As usual with ColdFusion, this is all
very nice and handy as long as your situation matches the default. But from the moment you have to customize a bit,
you can start pulling out your hair. And the fact is that the real world has this tendency not to match the default
situation.

For example: if the service you want to access has an endpoint that differs from the service url, you’re out of luck.
I found the following - completely undocumented - solution to use a custom endpoint:

My five-week old daughter is lying next to me on the couch and is telling me that I ought to show the interwebs the
beautiful birth card I made to announce her arrival in this world. Or at least, that’s what I gather from her babbling.
So without further ado:

Well, I finally found some time to dive into the Pixel Bender pool and start playing around with that new technology
that came from Adobe-land. And this is what I came up with for my very first attempt: nothing too fancy, just the Pixel
Bender version of the well known ”Pixelate” PhotoShop filter. Give it a whirl by adjusting the pixel size with the
slider. Flash Player 10 required of course.

Here’s a working example. Just play around with the Pixel size slider.

<languageVersion:1.0;>kernelPixelate<namespace:"net.riastar.shader";vendor:"RIAstar";version:1;description:"pixelates an image";>{inputimage4src;outputpixel4dst;parameterfloatsize<minValue:1.0;maxValue:20.0;defaultValue:4.0;>;voidevaluatePixel(){float2pos=outCoord();floatcenter=(size+1.0)/2.0;dst=sampleNearest(src,float2(pos.x-mod(pos.x,size)+center,pos.y-mod(pos.y,size)+center));//make sure not to sample outside the bordersif(dst.a&lt;=0.0)dst=sampleNearest(src,float2(pos.x-mod(pos.x,size),pos.y-mod(pos.y,size)));}}

I had quite a hard time getting it to work in ActionScript, apparently because I installed the Flex 3.3 SDK just a week
ago. Just putting a declaration of a flash.display.Shader class in my code, was sufficient to stop all code from
executing, although the VM did not crash. I also got no error message whatsoever.

So after a whole hour of trying everything I could think of, I told the compiler to use the old 3.2 SDK and tadaa:
working like a charm. Is it a bug in 3.3 (which was meant to be a bugfix release in the first place) or did I do
something wrong?