topleft
topright
Compiling a single PureMVC app to Flash and JavaScript ?
Sunday, 27 April 2008

If you've been using the AS3 Port and working with tools like Flex, Flash IDE, Aptana, FlashDevelop, or FDT amd targeting your work to the Flash Platform, using PureMVC and Flash together to create maintainable apps is nothing new to you. 

 

But maybe you're deeply entrenched in the AJAX world and are simply looking to augment your existing web applications with Flash where it makes sense for you and your customers. 

 

Lets say in your project, you want to coordinate several Flash based applications from JavaScript. You've heard that developing with an MVC framework in Flex, Flash and AS3 can positively impact the maintainability of the code, and naturally, you've found PureMVC is a great solution for that.

 

But:

 

  • You'd like to apply the same PureMVC development methodology to your JavaScript code as you do in your Flash and Flex apps.
 
  • Further, you'd like to see actual code reuse between the JavaScript PureMVC apps and the Flash or Flex PureMVC apps.

 

(Yes, that last one does sound like a pointy-haired boss requirement; one that could never, ever be achieved but it sounded possible from a flyer he read at a conference on SOA ...)

 

Unfortunately, in its current implementation, JavaScript is not truly object oriented. Working with objects and being object oriented are different things entirely. Without the ability to implement true classes, interfaces and inheritance, JavaScript has been all but ruled out as a potential target platform for PureMVC. Until now.

 

Enter the Haxe Port. 

Image

 

Haxe is an interesting proposition on the development landscape: With a single, familiar language, you can write applications that compile to JavaScript, Flash or the Neko VM.

 

And you even get support for targeting different versions of Flash. Some companies refuse to upgrade the plugins behind firewalls and so the ability to target prior versions is extremely important, since the communications between JavaScript and Flash have evolved a bit over time. 

 

Haxe has a pretty large and lively community base. You can even buy a book about it. But coming from the development silo of mostly Adobe tools like Flex, I admit I had marginalized Haxe's utility.

 

Sure, you can talk to JavaScript to and from Flash, but I had seen that code as nasty, disordered spaghetti that was best minimized. But when Marco Secchi showed me his PureMVC Haxe Port and what he was doing with it, I must admit my mind was forced to expand a little regarding what might be possible.

 

Here are a couple of extremely simple but eye-opening demos:


  • Simple Admin - [ Demo ] - [ Source ] - One codebase is used to create an application that runs in JavaScript or Flash. As you peruse the code, note how Marco has defined interfaces for certain classes that are then implemented separately for JavaScript or Flash. The JavaScript version of a class might traverse the DOM and use HTML to create its UI elements, while the Flash version uses drawing commands in a flash movie to achieve the same effect.  Otherwise much code is shared between the two applications.

  • MultiPlatform Communications - [ Demo ] - [ Source ] - A single application is compiled for JavaScript, Flash 8 and Flash 9. It displays a grey rectangle with a box inside it. In the surrounding page, a form with a text field and a send button, use JavaScript to send the number you input to the 3 applications, and they use it to reposition their contained boxes.

 

With so many JavaScript-based widget platforms out there, it seems like there could be a lot of potential here for leveraging public tools and libraries, while still being able to gain the advantage of structured code that PureMVC provides. I'm really looking forward to what the community will do with this Port. 


Check out the PureMVC Framework for Haxe today and see let us know what you think!

 

 

Delicious
Technorati
Reddit
Furl it!
NewsVine
YahooMyWeb
Stumble
blogmarks
Digg
co.mments
connotea
 

Who's on PureMVC.org

We have 33 guests online

OReilly PureMVC Book

PureMVC Book

PureMVC on the Web

PureMVC Blog-o-Sphere
PureMVC on Google+
PureMVC on Facebook
PureMVC on Twitter
PureMVC on Delicious
PureMVC on LinkedIn

Supporters of PureMVC

PureMVC on the Web

João Pescada has produced a nice PureMVC / AS3 demo - a searchable image gallery. 
 
Photo Search with PureMVC - Article  -  Code  -  Demo

 

 
Jonathan Campos has put together a nice introductory PureMVC article with an example built around the Netflix API.
 
Netflix API with PureMVC Article

 
The guys over at Pyjamas (a Python port of GWT) have made their compiler so efficient that it can take virtually any Python library and it will compile to Javascript. They loved the look of PureMVC Python, and decided to do a couple of demos that use it.
 

Pyjamas Project

• EmployeeAdmin Demo: Original / Pyjamas  

Pyjamas PureMVC Timesheet Demo

 
Chandima Cumaranatunge, co-author of the O'Rielly book AS3 Design Patterns, and long-time PureMVC community member recently created a simple Flash/AS3 MultiCore demonstration application accompanied by an informative article that's an excellent introduction to the benefits of working with MultiCore.
 
Who Moved the Cheese? - Demo / Source / Article

ActionScript 3 Design Patterns

 

Ahmed Nuaman has published a well conceived and received AS3/PureMVC tutorial at FlashTuts.com. It's a good place for the learner to get their feet wet, and goes into the difference between using PureMVC with Flex as opposed to Flash or pure AS3.

 

Understanding the PureMVC Open Source Framework

FlashTuts Website
Ahmed's Website

 

 

Recent Project Activity

The PureMVC MultiCore framework for  Native JavaScript is now available. It has no dependency on other frameworks and provides its own optional namespace and class simulation.

 

 

 

PureMVC Standard Version for Perl 1.0  has been released, complete with unit tests and online documentation.

 

PureMVC Standard Framework for Perl

 

Release 1.3 of the AIR DesktopCitizen Utility which allows applications to remember their window size, position and maximized/minimized state each time it is launched. It also provides a facility for requiring confirmation (or executing some shutdown process) before the application window closes.

 

AS3 / AIR Desktop Citizen Utility

CodePeek Demo

 

The classic PureMVC EmployeeAdmin Demo has been ported to yet another language! Although PHP is usually thought of as a server language, using PHP-GTK, Sasa Tarbuk recreates th a desktop app. 

 

 
Version 1.0.8 of the PureMVC Java MultiCore port is now available. It supports JavaFX and handles threading properly.

 

 
Copyright © 2006-2008 Futurescale, Inc.