topleft
topright

OReilly PureMVC Book

PureMVC Book

PureMVC TV

PureMVC TV

PureMVC on the Web

PureMVC Blog-o-Sphere
PureMVC on Google+
PureMVC on Facebook
PureMVC on Twitter
PureMVC on LinkedIn
PureMVC on Delicious
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
 
Copyright (c) 2006-2012 Futurescale, Inc.