Exploring Open Source Flash: What’s Available

In this topic, you will get a brief introduction to some of the open source tools that are available, including both the projects covered in the rest of the topic and some other noteworthy projects worth checking out on your own. We’ll cover three major categories of tools:

■    Development tools

■    Libraries and toolkits

■    Back-end, server-side technologies

These tools come from two major sources: the general open source community, which is often centered on the OSFlash.org website, and the open source initiatives that originated at Adobe to help further the Flash Platform. In this topic, we’ll look at the tools broken down by these two main contributors.

Community open source initiatives

“Community” open source projects constitute the projects contributed by individuals and companies unrelated to Adobe. Many of these started as internal company or personal projects that grew to the point where an open source development model could benefit both the people using the projects and the projects themselves.

Development tools

When doing Flash development, most people think of working in Adobe’s Flash IDE. The tools covered in the following sections represent an alternate workflow when writing ActionScript code and integrating it with assets from designers. These are compilers, development environments, and other useful Flash development tools.


MTASC

It acts as a full compiler and linker for ActionScript 2 projects and is able to create SWFs from your source code. It’s capable of compiling large amounts of code quickly, far exceeding the capabilities of the default compiler that comes with the Flash Platform.

Besides mimicking the functionality of the default Adobe compiler (MMC), MTASC introduces a few features to help aid good development practices. The first of these is preventing variables from being doubly declared in a function. For example, the following code will compile under MMC but will not compile under MTASC:

tmpeeee-1_thumb

Under the Flash runtime, there is only function-level scoping of variables. So, the for loop modifies the same variable that was declared before it, which leads to a common source of bugs. MTASC identifies these situations, and the compile will fail.

MTASC also doesn’t allow local function definitions. This provides an extra layer of compile-time checking for parentheses closure. MTASC does support anonymous inner functions assigned to a variable.

In MTASC, you can replace the default trace() method with a method you write. This allows you to implement extended logging capabilities, redirect the output to other locations, or ignore it altogether.

For more information about MTASC and to download it, visit the project website at http:// www.mtasc.org/.

ASDT

Eclipse is an open source development environment originally written for Java development. It has since been extended to work with a variety of languages from C++ to PHP. The ActionScript Development Tool (ASDT) is an Eclipse plug-in that brings ActionScript development to the Eclipse platform.

ASDT provides features such as the following:

■    Code completion

■    Code folding

■    Code navigator and exploration tools

■    Compilation using MTASC

■    Syntax checking

■    Syntax highlighting

■    Code templates

FlashDevelop

FlashDevelop is a Windows-only alternative to the Eclipse and ASDT environment. It supports ActionScript 2 and 3 development and supports many of the same features as ASDT, including the following:

■    Code completion

■    Code folding

■    Code navigator and exploration tools

■    Compilation using MTASC or the Flex SDK

■    Syntax checking

■    Syntax highlighting

■    Code templates

■    Version control system integration

In addition, FlashDevelop has a plug-in architecture to support additional features including support for other languages such as haXe.

haXe development tools

haXe is a modern, high-level programming language targeting web technologies originally written by the same author of MTASC.Like ActionScript, haXe can target Flash Player. Unlike ActionScript, it can also target a JavaScript or Neko runtime environment. Neko is a native system runtime environment (much like a Java JRE) that allows you to run haXe programs on a local system. It’s oftentimes used for server-side development.

Being able to target multiple types of runtimes means you can write your application in a single language. You can greatly reduce your development time by sharing code between your Flash application, your server-side back-end, and the JavaScript pages on your site. Many of the standard API calls for all three environments have been generalized in the haXe standard library, allowing a high degree of reuse between environments.

The haXe syntax is similar to ActionScript and should be easy for a veteran Flash developer to pick up.

You can learn more about haXe from the project website at http://www.haxe.org/.

swfmill

MTASC, the Flex SDK, and the haXe compiler all provide mechanisms for converting source code into compiled SWFs. swfmill provides a mechanism for compiling raw art assets into a SWF. Using swfmill, you can create SWFs that contain bundles of art assets or fonts. swfmill is capable of putting those assets into a library for use by ActionScript or, alternatively, placing an object directly on the viewable stage. swfmill is capable of pulling assets from the following:

■    Other SWF files

■    Compiled SWC files (component libraries)

■    PNG and JPEG images

■    SVG graphics (imported as vector graphics)

■    TrueType fonts

Once you create an asset SWF with swfmill, you can use MTASC to inject compiled ActionScript code into that SWF to provide an end-to-end development solution capable of replacing Adobe’s Flash IDE.

SWFObject

SWFObject is a set of JavaScript libraries and best practices for embedding Flash content into an HTML page. It provides features such as the following:

■    Flash plug-in version detection

■    Flash plug-in upgrades using the autoupdate feature

■    Support for a wide variety of web browsers and operating systems

■    Standards-compliant markup

■    Graceful fallback when embedding techniques fail, including allowing you to specify alternative content

■    A workaround for the “click to activate” functionality in the Internet Explorer and Opera browsers

Ant

Ant is a general-purpose Java-based build tool. Ant is meant to work alongside your ASDT builds, not to replace it.

As projects get more complex, the process of gathering components from different teams and assembling them becomes more and more complicated. Building through ANT allows you to maintain the integrity of your build cycle so you can be guaranteed that each build is made in the same repeatable way.

Imagine a situation where you are doing the ActionScript development, a designer down the hall is making the art assets for your project, and a web design firm in Turkey is creating the web pages in which your application will be embedded. Fully creating a new build might involve several steps:

1.    Copying files from your designer to the correct location in your build tree

2.    Downloading new content from the web design firm

3.    Actually building your application

4.    Copying your application, plus all that content, to a staging server

5.    At some later time, publishing everything to a live production server

Few things in software development are more frustrating then tracking down bugs that were caused by a missed step in the build cycle. By creating an automated build script, you’ll both make your life easier throughout the project and be able to guarantee a completely repeatable build process. Using Ant provides several advantages over using ASDT to make this easier:

■    You can copy, delete, and move both files and directories.

■    You can deploy your application over FTP, WebDav, or SSH.

■    You can invoke other build tools, such as swfmill, automatically.

■    You can create a build environment that others, who may not be using ASDT or FlashDevelop, can use.

■    You can integrate build scripts into automated build environments.

Sprouts

Although not covered in this topic, Sprouts is a new open source project aimed at making it easier to set up and maintain a Flash development environment. Sprouts is capable of creating and managing the configuration of ActionScript 2, ActionScript 3, and Flex-based projects.

You can learn more about Sprouts at the Sprouts website (http://www.projectsprouts.org/).

Libraries and toolkits

A large part of the effort put in by the open source community is in producing various libraries or toolkits to make development easier. In this topic, we’ll be looking at a few of those including Fuse Kit and Papervision 3D. Besides these, there are many more; you can find a list of a few of them at the end of this topic.

Fuse Kit

Fuse Kit, often referred to simply as Fuse, is a development library by Moses Gunesch that combines a tweening engine and sequencer to provide a powerful code-based animation solution for Action-Script 2 development. Using Fuse you can easily set up complex sets of animations without the need of callback functions, timers, or extensive calls to the Tween class.

The tweening engine allows you to animate all of the usual Flash properties (such as changing the x coordinate of an object to move it across the screen), plus all other properties of an object, and it even includes filter tweening.

The sequencer allows you to set up chains, or fuses, of tweens to create complex animation effects that are timed and sequenced with each other.

To give an idea of the power of Fuse, here is a simple example from the Fuse Kit documentation that moves a MovieClip in a rounded square.

tmpeeee-2_thumb

This example shows off the simplified syntax of the tweening engine, and the first four lines represent the movement of an object in four different directions. The sequencer kicks in by executing each of these tweens sequentially without the need for the developer to determine when each part of the animation should start or stop.

Papervision3D

Papervision3D is a full-featured 3D rendering engine for Flash Player. Using Papervision3D you can create simple 3D effects such as rotating planes or cubes or complex fully interactive 3D environments. Versions are available for both ActionScript 2 and ActionScript 3 depending on your needs.

Screenweaver HX

Screenweaver HX is largely written in haXe and runs in the Neko runtime environment. Using Screenweaver HX, you can host the Flash plug-in in a window and load SWFs created with either ActionScript or haXe (or any other technology capable of creating SWFs). Using this technology, you can create desktop applications in Flash that have access to local resources, such as read/write access to files, and also leverage all the capabilities of the Flash Platform.

You can find out additional information or download Screenweaver HX from http://www. screenweaver.org/.

Server-side technologies

Much of the focus on Flash development is focused on the visual front-ends, but the server back-end can be just as tricky to get right. In the following sections, we’ll explore two open source technologies—AMFPHP, SWX, and Red5—that help to create robust and scalable back-end solutions with a minimum amount of effort.

AMFPHP

The Action Message Format (AMF) is a binary data exchange format optimized for the Flash Platform. AMFPHP is one server-side implementation of this format and is the oldest of the three server-side solutions we’ll be covering. AMFPHP provides Remote Procedure Call (RPC) functionality allowing Flash applications to call server-side functions. In addition to supporting AMF, it can communicate via JavaScript Object Notation (JSON) and XML-RPC. These last two options open the possibility of talking to AMFPHP using client-side technologies other than Flash.

AMFPHP allows you to focus on the domain-specific logic of your application instead of worrying about the transport mechanisms used to send data back and forth between the server and client. It’s designed to be a lightweight and unobtrusive solution that is applicable to a wide variety of development approaches.

As the name implies, AMFPHP is written in PHP, allowing it to be used on a wide variety of inexpensive web hosting environments. It doesn’t require any special PHP extensions. Anyone with knowledge of PHP should be able to quickly learn how to develop an AMFPHP application.

Red5

Red5 is an open source project focused on delivering a full Flash remoting development environment. Like AMFPHP, it provides RPC functionality over AMF. Unlike AMFPHP, it also provides streaming media and server-side shared object support.

Video and audio media can be streamed to the client, replicating much of the functionality of the Flash Media Server (FMS). Video or audio can also be recorded from the client’s webcam and microphone and sent back to the server for further processing or distribution.

Shared remote objects give Flash clients a way to keep data synchronized across different clients and give them a mechanism to push data from the server to the client. Some example applications using this functionality might include a real-time chat room or a multiplayer video game.

Red5 is a Java-based server with stand-alone and J2EE-hosted versions. It’s built on standard Java technologies such as Spring, Mina, and Jetty.

SWX

SWX is a relatively new server-side technology.It uses the SWF format for data exchange, which provides a few significant advantages over other transport mechanisms:

■    Support for Flash Lite development

■    Natively understood by Flash Player for a minimum of processing time

■    Extremely easy to use

SWX provides an RPC mechanism allowing Flash to directly make calls into the server. Unlike AMFPHP or Red5, there are several server-side implementations of SWX:

■    SWX PHP: http://swxformat.org/documentation/swx-php/

■    SWX Ruby, http://swxruby.org/

■    SWXJava: http://www.swxjava.org/

An example of using SWX from Flash follows:

loader.serviceClass = "Flickr"; loader.method = "swxPhotosGetRecent"; loader.debug = true;

loader.loadMovie("http ://swxformat.org/php/swx.php", "GET");

Adobe open source initiatives

In recent years, Adobe has recognized the benefits of the open source development model for several of its projects and has launched a website dedicated to open source at http://opensource. adobe.com/. This includes the Flex 3 SDK development toolkit, the BlazeDS server-side solution, and several ActionScript 3-based libraries.

Flex 3 SDK

The Flex 3 SDK package is Adobe’s official development environment for ActionScript 3 development using the Flex framework and targeting Flash Player 9 and newer. In April 2007 Adobe announced its intention to make the entire Flex SDK open source. Since then, Adobe has made the SDK publicly available for free, with the full source to the framework code including access to the source code of all the tools (compiler, debugger, and so on) and the framework. Adobe has also made the bug-tracking system open to the public.

You can currently find more information at the following locations:

■    The Flex 3 SDK: http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK

■    The Flex bug-tracking database: http://bugs.adobe.com/flex/

Although the core SDK is open source, Flex Builder is not part of Adobe’s open source initiative and will remain a commercial product. Likewise, its Flash authoring environment remains a commercial endeavor.

There is also a set of additional charting components that come exclusively with Flex Builder Professional, which is also not part of the open source initiative.

BlazeDS

BlazeDS is a Java-based server solution offering real-time communication services for the Flash Platform. It consists of three major components:

■    A remoting service to access server-side methods and objects

■    A messaging service for a publish/subscribe messaging support

■    A proxy service to allow Flash applications to access types of data not usually allowed under the Flash security sandbox

BlazeDS can be installed on a J2EE-based server or run stand-alone using the BlazeDS turnkey server. You can find both deployment options, as well as access to the source code, at the BlazeDS website (http://opensource.adobe.com/wiki/display/blazeds/BlazeDS).

ActionScript 3 libraries

In addition to the large, officially funded projects at Adobe, several ActionScript libraries are written and maintained by Adobe staff members. Some of those libraries include the following:

■    as3ebaylib is a library for accessing eBay’s XML API through ActionScript. You can find it at http://code.google.com/p/as3ebaylib/.

■    as3corelib is a collection of classes and utilities that make ActionScript development easier. You can find it at http://code.google.com/p/as3corelib/.

■    as3flexunitlib is a unit testing framework for Flex development.

■    as3odeolib is an ActionScript library for retrieving podcasts from the Odeo service. You can find it at http://code.google.com/p/as3odeolib/.

■    as3youtubelib is a library for accessing the YouTube data API. You can find it at http:// code.google.com/p/as3youtubelib/.

■    as3syndicationlib provides a single interface for dealing with RSS and Atom feeds. You can find it at http://code.google.com/p/as3syndicationlib/.

■    as3flickrlib is a library for consuming the Flickr API. You can find it at http://code.google. com/p/as3flickrlib/.

■    as3mapprlib provides access to the Mappr API that combines Flickr and geo-tagged information. You can find it at http://code.google.com/p/as3mapprlib/.

■    Cairngorm is a framework for developing Flex-based rich Internet applications. You can find it at http://labs.adobe.com/wiki/index.php/Cairngorm.

And many more …

As you’ve seen in this topic, a lot of open source projects are available for Flash development. The rest of this topic looks at a few of those projects. But the best thing about open source Flash is that new projects are starting all the time. Visit Flash community blogs, read the OSFlash mailing list, and do the occasional Google search since you never know what useful and amazing projects you’ll find.

We’ll end this topic with a list of a few projects not covered in this topic that are still worth checking out:

■    AlivePDF is an ActionScript library to generate PDFs. You can find it at http://alivepdf.org/.

■    ARP is a lightweight development framework. You can find it at http://osflash.org/ projects/arp.

■    AsWing is a GUI framework and set of ActionScript components. You can find it at http:// www.aswing.org/.

■    Degrafa is a Flex library for creating a drawing API in MXML. You can find it at http://www. degrafa.com/.

■    FlexLib is a set of Flex-based components ranging from an animated fire effect to a full schedule display framework. You can find it at http://code.google.com/p/flexlib/.

■    GoASAP is a lightweight framework for building ActionScript 3 animation tools. Its main contributor is Moses Gunesch, also the author of Fuse. You can find it at http://www.goasap.org/.

■    ObjectHandles is a Flex library that helps you build an interface to allow users to move and resize objects on the screen. You can find it at http://www.rogue-development.com/ objectHandles.html.

■    Pulse Particle System is a general-purpose particle library that includes an interactive particle explorer to help you create visual particle effects. You can find it at http://www.rogue-development.com/pulseParticles.html.

■    Sandy is an ActionScript 2/ActionScript 3 3D rendering engine. You can find it at http://www. flashsandy.org/.

■    Several projects are located at the Spicefactorywebsite (http://spicefactory.org/). These include Spicelib, a library for task management, reflection, and logging; Parsley, an Inversion of Control (IoC) container, MVC framework, and localization utility; and Cinnamon, an ActionScript 3/Java remoting solution.

■    Prana is an application framework centered around an IoC container. You can find it at http ://www.pranaframework.org/.

■    Tweener is an ActionScript 3 tweening engine usually used to create both simple and complex animations. You can find it at http://code.google.com/p/tweener/.

Next post:

Previous post: