AS Frameworks

Recently I’ve been looking into different frameworks, just to get some experience with other interesting frameworks out there. I’ve compiled a list of some of the frameworks I’ve found. I’m sure I’ve missed a couple of other good ones, if you know of one, please let me know. 🙂

Gaia
A framework package as a Flash component. Handy for designers, but it kinda made me shrug… Though reading through the docs a couple of interesting features showed through, like the generation of the navigation through the context menu.
Link: http://www.gaiaflashframework.com/index.php

Cairngorm
Used this framework / micro architecture a lot already. Nice Event-Command pairs as well as delegates for calling all (web)services.
Link: http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm

PureMVC
I’ve been working with a PureMVC project lately and looked at it before, quite similar in some ways to Cairngorm, just different names. 😉
A nice resource for pureMVC: http://puremvc.tv/
Link: http://puremvc.org/

Swiz

Swiz is a framework for Adobe Flex that aims to bring complete simplicity to RIA development. Swiz provides Inversion of Control, event handing, and simple life cycle for asynchronous remote methods.

Link: http://code.google.com/p/swizframework/

Dawn

Dawn is a lightweight framework for ActionScript inspired by Google Guice. In addition to Dependency Injection, it provides type safe notifications and helps you to build apps which are loosely coupled, easily unit tested, and less error-prone.

Link: http://wiki.github.com/sammyt/dawn

Mate

Mate is a tag-based, event-driven Flex framework.

Mate framework has been created to make it easy to handle the events your Flex application creates. Mate allows you to define who is handling those events, whether data needs to be retrieved from the server, or other events need to be triggered.

In addition, Mate provides a mechanism for dependency injection to make it easy for the different parts of your application to get the data and objects they need.

Link: http://mate.asfusion.com/

I think I’m going to give Dawn a try soon enough, of all the above it looks the most interesting to me.

AS3 Version Injection + Flex PMD + TDSI = Rock ‘n Roll! \m/

Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510 Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513

AS3 Version Injection

Ever been annoyed by Project Managers telling you that a bug you fixed is still in the latest release you did and after some investigation find out that they forgot to clear their cache? Well, fear not! An AS3 Version Injection script is here! 😛
I’ve created a simple AS3 class called Version that will add a time stamp to the context menu. All you need to do is instantiate the Version class once and pass it a reference to you Document Class. On top of the AS I’ve written a little Ant script that will take a template of the Version class, insert the current date and time and write out the Version class. This way you can just make it part of your Ant build and don’t need to worry about manually updating the version number. Also, now you’ll have a way of quickly identifying what version somebody is looking at. 🙂

Flex PMD

This is great for auditing your own code as well as other people’s code. I’ve written a small Ant task that can be ran as part of a build that will run your project through Flex PMD and create a PMD file for you. The PMD file will have a time stamp suffix so you don’t overwrite your old file and you can compare issues. To use this Ant script make sure you’ve downloaded PMD for Ant.

TDSI

Another piece of very useful technology. Up to 20% performance increase just by passing your SWF through it. I downloaded the Apparat source (where TDSI is part of) from Google Code and compiled it. Built another little Ant script to use TDSI with Ant. Just specify the input and the output file and you’re done!

Bringing it all together

All the above Ant scripts are saved in a separate file. This way I can import whatever piece I want in my build script, example:

  1. <import file="as3_version.xml" />

TIP: Place the import after you have defined your properties in the build script, this way the imported scripts can use the properties set in the build script.

Links

Flex PMD

Nice! A Flex (automated) auditing tool! 🙂

FlexPMD is a tool that helps to improve code quality by auditing any AS3/Flex source directory and detecting common bad practices

Would be interesting to start using this.

Gotcha:
The PMD Violations Viewer only accepts files that are named “pmd.xml”, all other files will not be recognized. I run an Ant task to rename the generated pmd.xml to pmd_[insert timestamp here].xml. When I tried uploading the renamed file the PMD Violations Viewer wouldn’t accept it. 🙁

Links:

Flash on the Beach 09 – Play with Vectors

Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510 Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513 Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510 Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513 Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510 Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513

This year I was only able to go to Flash on the Beach on the very last day. Never the less it was once again a really awesome experience and I learned a lot and got a lot of inspiration as well. I’ll try and post my notes from all the talks I’ve seen, but it might take a while…

23-09-2009 9.00 Koen de Wieggheleire – Play with Vectors
Koen did a very in depth talk about the Vector class in AS3.

The Vector class is a dence array which means that it can’t have any gaps, so something like the below would throw an error:

  1. myVector[0] = 'bla'; // See how we're skipping positions 1 and 2?
  2. myVector[3] = 'something else';

You can you an array as a ‘data provider’ to populate a Vector:

  1. myVector = Vector.<String>(myArray);

Using the Vector class will give you a performance boost of about 40 to 60%.
Unfortunately you can’t directly bind to a Vector in Flex, you can however write a wrapper class and bind to that. 😉

How to use in 3D

The Matrix3D class is somewhat complex to understand, but the image below should clarify it a bit

You can use myDisplayObject.transform.matrix3D to retrieve a DO’s Matrix3D or assign a new matrix3D to it. There are also build in methods to user rather than creating a new Matrix3D all the time, see http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html

Nice thing I only found out now about matrixes: You can skew objects with it! Rock on!!! \m/

How to use with 2D

Pretty much the entire graphics API in Flash relies on Vectors. The drawPath() method below (which is pretty much the core of drawing vector shapes) takes two Vectors (the Vector data type) as arguments.

  1. graphics.drawPath(commands, data)
  • the commands argument is a Vector containing GraphicPathCommands
  • the data argument is a Vector containing x and y pairs that determine the path to draw.

The new Illustrator can export to FXG and you can actually import this FXG data on the fly in Flash, parse it and draw the exact same.

Some notes on UVT (texture) mapping:

  • U matches up with the x location
  • V matches up with the y location
  • T determines the focal length

The right value for T can be calculated with the following formula: T = focalLength / (focalLength + z)

Useful links:

MXML and code behind

I’m a big fan of keeping MXML files clean by not having any code and style information in them. You can get rid of the style information by using a style sheet. A nice way to get all of your code out of the MXML is by using the code-behind method.

Code-behind encourages developers to build applications with separation of presentation and content in mind. In theory, this would allow a web designer, for example, to focus on the design markup with less potential for disturbing the programming code that drives it.

There is a good article by Aral Balkan at the Adobe Devnet on using the code-behind method with Flex.

Links:

Creating a SWC

Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510 Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513
  1. compc -output=C:\something.swc
  2. -sp C:\Projects\test\src
  3. -is C:\Projects\test\src

This works much faster than just adding all classes by hand when using include-classes (or ‘ic’) and needing to specify each and every class…