GradleFX @ Belgian Flex Usergroup (live blog)

ActionScript, Air, Flash, Flex No Comments »

Yennick Trevels is speaking about GradleFX this evening. The session starts at 19:00 CET. Check back here for updates and feel free to ask questions in the comments. Please use the #beflug hashtag when tweeting about this event.

What is GradleFX

From the website: “GradleFx is a Gradle plugin for building Flex and Actionscript applications. It provides a set of useful tasks that will make building your project a breeze. All the build logic is encapsulated by the plugin and all you need to do is some configuration. Because GradleFx uses the convention-over-configuration principle it has a set of sensible defaults for most configuration properties, so you only need to specify those if you want to deviate from the convention.”

More info:

What is Gradle

From the website: “Gradle is build automation evolved. Gradle can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else.

Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build. Powered by a Groovy DSL and packed with innovation, Gradle provides a declarative way to describe all kinds of builds through sensible defaults. Gradle is quickly becoming the build system of choice for many open source projects, leading edge enterprises and legacy automation challenges.”

More info:

Session notes (live)

19:20 Here we go! About 15 people in the room.

19:25 Yennick explains Gradle before diving into GradleFX. Show of hands of Ant and Maven users. Most have used both. Gradle combines the best of both worlds Yennick states.

Gradle has built-in tasks for compiling and testing etc, but you can create your own tasks as well. Everything is written in Groovy. Gradle uses Configuration Injection instead of configuration inheritance like Maven for subprojects.

19:30 Yennick shows how to create a simple task in Gradle and how you can configure existing tasks. Executing a task: command line > “gradle {taskName}”

19:35 Example of a custom task class in Groovy. You can extend DefaultTask and provide custom task logic.

Default properties in the build scripts allow you to have small build scripts if you use the conventions.

Remote repositories can be used from Ivy and Maven repositories. You can add mavenCentral(), mavenLocal(), or a custom repository in the “repositories” section.

19:40 Gradle has a 3-phase build: initialization, configuration, execution.

You can use project.afterEvaluate to add extra tasks or properties after the configuration is read. This allows you to add certain tasks conditionally, e.g. add package task only if the project is an AIR application. allows you to execute Ant code from Gradle. You can use to read Ant defined properties.

19:45 Maven support in Gradle: you can locally install artifacts to your Maven repository.

Gradle Wrapper is a shell script that run Gradle even if you don’t have Gradle installed. You can specify the Gradle version to make sure people build your project with the correct Gradle version. Use “gradlew” to execute.

19:50 Now to GradleFX. Adds tasks to compile SWF, SWC and AIR, running unit tests and generating HTML wrappers.

Tasks: clean, compile, package, copyResources, publish, createHtmlWrapper, test

19:55 Setup: specify FLEX_HOME environment variable or set the flexHome convention property.

The GradleFX dependency is org.gradlefx.gradlefx, currently version 0.4.1

20:00 You can also generate AIR descriptor files and certificates in PKCS12 format, a password is required.

FlexUnit support: specify the FLEXUNIT_HOME and the FLASH_PLAYER_EXE environment variable.

20:05 Taking a short break. Demo time when we return.

20:25 Demo time.

Add to Bloglines - Digg This! - - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner

Introducing AS3Commons AOP

ActionScript, AOP, AS3Commons, Flex, Java 11 Comments »

The AS3Commons AOP library offers a core API with functionality to implement Aspect Oriented Programming (AOP) concepts in your application or framework. The library uses standard API terminology so that developers who are already familiar with AOP should feel immediately comfortable.

What is AOP?

For those new to AOP, here is a short explanation of the general idea. (If you are already familiar with AOP concepts, you might want to skip this part and go directly to the examples).

The basic idea behind AOP is that an application can be broken down into functional parts that can be conditionally applied to existing code. A classic example is logging, where debug information about certain methods is written to the console in order to get runtime information about the execution of the code. One approach might be to add log statements at the beginning and the end of the methods that you would like to debug. This is quite a tedious task as you need to manually add code to several places. If you ever wanted to get rid of the log statements, you would have to remove the log statements again. With AOP, you can write the logging code in a separate class and then use that class as an Advice on the class that you want to debug. You can then easily reuse the logging code on other methods of other classes.


  • Aspect: the general concept of a cross-cutting concern. Logging, Error Handling, Method Run-Time Monitoring are useful examples.
  • Advice: an extra piece of code that needs to be applied. E.g. writing a log statement to the console.
  • Pointcut: a rule about when an Advice should be applied. For instance: all public methods of a class, all methods starting with "load", all methods that take a String parameter, ...
  • Advisor: the combination of an Advice and a Pointcut. This term is not general AOP vocabulary. It was introduced in the Spring AOP framework and is also used in AS3Commons AOP.
  • Joinpoint: a single point in the execution of the code where Advice is applied because the rule of a Pointcut has been satisfied.

Types of Advice

Advice comes in different forms, depending on what and when you want to intercept. The general types are listed below and can be applied to a Constructor, a Method or an Accessor (Getter/Setter):

  • Before: executes before the invocation
  • After: executes after the invocation
  • After Throwing: executes after the invocation threw an error
  • After Returning: executes after normal invocation (when no error was thrown)
  • Around: combines all of the above

The AS3Commons AOP library contains interfaces for all of these kinds of advice. This makes it fairly easy to implement specific advice. Interceptors can also be created that give the developer more control over the invocation than the basic advice interfaces.

How does this work?

Applying Advice to existing code is done at run-time. For this, we create a typed-proxy (also at run-time) of a class or instance that is basically a decorator (or wrapper) around the original class or object that we created. A client then works with the proxy object instead of the original object, which is completely transparent to the caller. Calls to the proxy object are then redirected to the inner (original) object during which extra logic can be executed.

Note: Creating typed-proxies at run-time is made possible by the AS3Commons-Bytecode library.


Consider the following MessageWriter class, which takes an optional message as a constructor argument and has a method to write the message to the console.

  1. public class MessageWriter {
  3.   private var _message:String;
  5.   public function MessageWriter(message:String = "") {
  6.     _message = message;
  7.   }
  9.   public function writeMessage():void {
  10.     trace("Message: '" + _message + "'");
  11.   }
  13. }

We can now create an advice that writes an extra message to the console whenever the writeMessage() method is called. This type of advice is "method before" advice, for which the IMethodBeforeAdvice interface can be implemented.

  1. public class MethodTracerAdvice implements IMethodBeforeAdvice {
  3.   public function MethodTracer() {
  4.   }
  6.   public function beforeMethod(method:Method, args:Array, target:*):void {
  7.     trace("* before '" + + "'");
  8.   }
  10. }

We can now create a simple application where a proxy is created for the MessageWriter class and the MethodTracerAdvice is applied.

  1. var factory:AOPProxyFactory = new AOPProxyFactory();   
  2. = MessageWriter;
  3. factory.addAdvice(new MethodTracerAdvice());
  5. var handler:Function = function(event:OperationEvent):void {
  6.   var messageWriter:MessageWriter = factory.getProxy(["Hello World!"]);
  7.   messageWriter.writeMessage();
  8. };
  10. var operation:IOperation = factory.load();
  11. operation.addCompleteListener(handler);

The console output would be as follows:

  1. * before 'writeMessage'
  2. Message: 'Hello World!'

Notice the following things:

  • The target of the AOPProxyFactory is a class. For now, only classes can be proxied but it will also be possible to proxy existing instances.
  • The MethodTracerAdvice class implements the IMethodBeforeAdvice interface. This allows the framework to know when the advice must be executed, namely before the method invocation.
  • There is an asynchronous step in loading the proxy factory, after which the proxy can be requested. If you want to create proxies for more classes, consider using the AOPBatchProxyFactory instead. Note that even with the AOPProxyFactory, you can get multiple instances of a proxy.
  • You can pass constructor arguments to the proxy factory that will be used when creating the proxy. Although not shown in this example, it is possible to intercept and change the constructor arguments using an IConstructorBeforeAdvice.

Example with Pointcut

The previous example applies the "method before" advice on every method call. If we would add another method to the MessageWriter class, say "writeAnotherMessage", then the advice would also be invoked on that method. To control when this advice is applied, we can specify a Pointcut that will instruct the framework about when to apply the advice.

Here is the modified MessageWriter class and example.

  1. public class MessageWriter {
  3.   private var _message:String;
  5.   public function MessageWriter(message:String = "") {
  6.     _message = message;
  7.   }
  9.   public function writeMessage():void {
  10.     trace("Message: '" + _message + "'");
  11.   }
  13.   public function writeAnotherMessage():void {
  14.     trace("Message: 'Konnichiwa!'");
  15.   }
  17. }

  1. var factory:AOPProxyFactory = new AOPProxyFactory();   
  2. var pointcut:IPointcut = new MethodNameMatchPointcut("writeMessage");
  3. var advice:IAdvice = new MethodTracerAdvice();
  4. factory.addAdvisor(new PointcutAdvisor(pointcut, advice));
  5. = MessageWriter;
  7. var handler:Function = function(event:OperationEvent):void {
  8.   var messageWriter:MessageWriter = factory.getProxy(["Hello World!"]);
  9.   messageWriter.writeMessage();
  10.   messageWriter.writeAnotherMessage();
  11. };
  13. var operation:IOperation = factory.load();
  14. operation.addCompleteListener(handler);

The console output would now be as follows:

  1. * before 'writeMessage'
  2. Message: 'Hello World!'
  3. Message: 'Konnichiwa!'

Notice the following:

  • A Pointcut is defined to specify that advice should only be applied if the method name is "writeMessage"
  • The Advice and Pointcut are defined separately and then combined with a PointcutAdvisor. This allows us to reuse Pointcuts and Advice in other scenarios.

Other Types of Advice

The examples shown above only show IMethodBeforeAdvice, but there are a lot more advice interfaces that you can use. As mentioned earlier you can also intercept after invocation. This is not limited to method invocations, but you can also do this for Constructors, Getter and Setters. (Note that there are still some glitches in the alpha code concerning these types of advice.)


The current code is not production ready, but is certainly worth a look if you are interested in using AOP in your application or framework. We will release a first alpha release in the coming days with some samples and documentation. You can already check out the code at the AS3Commons Google Code site.

It is still early in the development so the API might change a bit before the official 1.0 release. If you have any ideas or comments about certain implementations, we're always eager to hear from you.

Some of the things on the roadmap that should make it into the release:

  • AspectJ expression language for pointcuts
  • Composite Pointcuts
  • Proxying of existing object instances

Looking forward to hearing your thoughts and enjoy coding!

Add to Bloglines - Digg This! - - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner

Programmaticaly sorting a column in an AdvancedDataGrid

ActionScript, Flex, tips 'n tricks No Comments »

Here's a quick tip: If you want to sort a column of an AdvancedDataGrid, without having to set up a sort on the dataprovider, you can dispatch an AdvancedDataGridEvent of type AdvancedDataGridEvent.SORT from the datagrid.

This can be useful if you have a custom sort function on a datagrid column and you want the datagrid to be sorted initially without requiring the user to click the column header.

  1. var sortEvent:AdvancedDataGridEvent = new AdvancedDataGridEvent(AdvancedDataGridEvent.SORT);
  2. sortEvent.columnIndex = 0; // first column
  3. dataGrid.dispatchEvent(sortEvent);

Add to Bloglines - Digg This! - - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner

Spring ActionScript 1.1 Released

ActionScript, Air, Flash, Flex, Inversion of Control, Spring ActionScript 3 Comments »

Dear community,

We're pleased to announce that Spring ActionScript 1.1 is now available.

Download | API Documentation | HTML Docs | Changelog

Besides a series of bugfixes, this release adds the following new features and enhancements:

Component Scanning & Context XML Namespace

Just like XML and MXML configuration, component scanning is a way to configure objects to be used in the application context. This is done by adding [Component] metadata to classes that you want to expose as objects to the container. The container will then scan all classes or the classes in a package you specify and create object definitions for the classes that have Component metadata. This means that you can configure your application with a minimum of XML or MXML configuration.

The newly added "context" namespace currently contains a "component-scan" and a "metadata-config" element. The first one enables component scanning as described above. The "metadata-config" registers common metadata processors and reduces the configuration needed to use these processors.

  1. <context:component-scan/>
  2. <context:metadata-config/>

For more info, see the documentation: Component Scanning

Test Framework

The Spring ActionScript integration testing support framework provides several abstract support classes that can simplify writing integration tests. These base test classes provide well defined hooks into the testing framework. Currently, only FlexUnit 4 is supported.

More info can be found in the Test Framework section of the documentation.

PostConstruct, PreDestroy and Inject Metadata

To be in line with industry standards, we added support for the PostConstruct, PreDestroy and Inject metadata.

PostConstruct and PreDestroy are annotations that allow you to call methods in a specific phase in the lifecycle of a component. The Inject metadata is used as an alias for the Autowired metadata.

More Information

For more general information on the Spring ActionScript framework, please see the following links:

Enjoy this release and have fun coding!

Add to Bloglines - Digg This! - - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner

Spring ActionScript 1.0 Released

ActionScript, Flex, Inversion of Control, Spring ActionScript 2 Comments »

Dear community,

We're pleased to announce that Spring ActionScript 1.0 is now available.

Download | API Documentation | HTML Docs | Changelog

Spring ActionScript is an offshoot of the Java Spring Framework written in ActionScript 3.0. The framework contains the following core features:

  • Inversion of Control container, configurable with XML or MXML
  • EventBus supporting loose communication between application components
  • Metadata/annotation processing used for autowiring, event handling, ...
  • Operation, Command and Task API
  • Utilities for abstracting server communication
  • Support for Modules
  • Extensions for the Cairngorm and PureMVC frameworks

The Spring Actionscript team would like to take this opportunity to thank everyone who took the time to report bugs, give suggestions and help out in any other kind of way. Without the dedicated Spring community behind us, the framework would not be where it is today. Thank all of you!

We would also like to thank the nice folks at SpringSource and especially Jeremy Grelle, our project sponsor, and Russel Miles, the Spring Extensions lead. Thanks guys for the support and the opportunity that you gave us.

As always, we're on the look out for new members to join the team. If you are willing to invest some of your spare time to write documentation, sample applications, fix bugs or develop new functionality then please don't hesitate to get in touch with us!

For the full list of changes please check the changelog. If you have any suggestions for new functionality or improvements to the existing code base, then please use JIRA to submit a feature request.

More Information

For more information on the Spring ActionScript framework, please see the following links:

Enjoy this release and have fun coding!

Add to Bloglines - Digg This! - - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in