Goodies for Flex2 Developers

I was invited by Adobe to join them in San Francisco for the two day Adobe Component Developer Summit (ACDS) last month. The event was a blast to say the least, surely the best developer get-together i’ve been to ever. I got to finally meet people that i know for many years now but never met before (you know wo you are), and the presentations were all very solid.

Ted Patrick (he set the whole thing up and receives my special thanks once again: was great meeting you, Ted) announced today that the speakers made their slides (and sample code where applicable) available to the public. It’s absolutely a great resource for developers who want to get their feet wet with Flex 2, or who want to dig deeper. My personal favourite presentation was Gary Grossmans “ActionScript 3.0 and AVM2: Performance Tuning” [PDF].

Check out Ted’s post “Adobe Component Developer Summit – Slides and Examples” for the download links.

[Oh and by the way, in case you missed it, the price winning and dug Commodore C64 emulator project FC64 that Darron Schall and myself have been working on in our free time for a while now is an open source project so feel free to check out the sources to see how we did it. Maybe you even want to contribute.. please drop me or Darron a mail, we greatly apprechiate your input]

Innovation, or the lack thereof… W3C, anyone?

I originally posted this on the OSFlash mailinglist, but i thought it would make a good blog post, so here it is:

My vision of a next generation web application framework.

(or: Innovation, or the lack thereof… W3C, anyone?)

There’s a sh*tload of XML dialects for GUIs either available or being developed at the moment. Just to name a very few: Adobes MXML, Microsofts XAML, Laszlos LZX, Netscapes XUL, and from the OSFlash camp ActionSteps ASML (or Renaissance) and ASWings AWML.

All of them are proprietary formats (plus most of them are direct projections of the underlying, proprietary APIs), and all of them require some decent amount of script code to be written in order to actually make the UIs work. Problems: to author sophisticated applications i need extensive knowledge of the XML dialect itself, of the API and the scripting language, and probably of the underlying platform API too. For most ‘next gen’ RIA platforms much of this is proprietary stuff, so i better choose wisely what technology to dive into for the next months/years. I also better be able to think ‘code’ in order to make my RIA a successful reality.

Wouldn’t it be nice to develop web applications using open, standardized technologies that everyone is already very familiar with? Let me introduce you to the W3C, and please try to forget about browsers in general and men with white beards wearing birkenstocks in particular for a moment.

Contrary to popular belief, the W3C is working on really cool stuff. Some of it you’re already very familiar with: (X)HTML and CSS. The *real* cool stuff though are W3C technologies that haven’t made it into the mainstream yet (because they aren’t supported by mainstream clients, or because they’re being worked on yet). I pick two of those technologies, XFrames and XForms, and briefly introduce them here, as i think that together with XHTML (2) and CSS (3), they pretty much cover everything a RIA framework needs.

XFrames
The technology that is supposed to supersede HTML Frames. XFrames of course is going to support framesets as we know (and hate) them today, but there’s so much more. Using CSS, frames can be styled to appear as floating windows or tabbed panes for example, and using a new URI scheme it will be possible to easily link not only a frameset but also it’s content, example: http://example.org/index.xframes#frames(id1=uri1,id2=uri2,...).

XForms
The technology that is supposed to supersede HTML Forms. XForms is going to significantly change the way we author forms. Basically, it separates the model from view and controller, as you can now have multiple data instances (usually XML, both inline or external) that you can use as data provider for controls and widgets (controls can be bound to data provided by instances using XPath). Validation is handled in a purely declarative way via XML Schema datatypes. But again, there’s much more, for example: <switch> and <case> to show/suppress parts of the UI (to be used for e.g. wizards, tabbed interfaces or dynamic forms), or <repeat> (to be used for e.g. filling tables with rows, or datagrids, or just about anything UI that repeats itself). Of course everything is styleable by CSS and can be bound to data instances. Sounds familiar? It sure is. And did you know that the latest ColdFusion uses XForms under the hood? Yes it does.

I recommend the W3C articles “XForms for HTML Authors” (Part 1 and Part 2) and Micah Dubinkos XForms Institute (hey look, he’s using DENG!) for a leightweight introduction to XForms (The XForms Institute also links a free online version of the O’Reilly book “XForms Essentials” in case you’d like to dive in further)

If you mix all those technologies mentioned above, and throw in some more, like SVG, SMIL, and maybe even XUL, that’ll be my vision of a sane platform for Web 2.0 [sm][tm](c)… ok, Web 3.0 it is then. A sane platform to develop RIAs on. Don’t even get me started ranting about the current state of the web as too many people see it. What the web needs is innovation, not hyped acronyms for old crap, or yet another proprietary markup language.

Of course such a framework needs to be developed yet. With the Flash Player 9 in our hands, the great performance boost compared to version 8 and a way better API (minus native text rendering.. still sucks), i’m sure it’s absolutely doable. If only somebody with some angel $$ would share my views, or if only everybody would work together with open minds instead of cooking their own soup…

We even have a proof of concept, anybody remember DENG? That was Flash Player 6. I’m also writing all this because i think most people misunderstood DENG and see it as a better HTML-enabled TextField or something, or worse, as a HTML browser. It was supposed to be the beginning of an application framework. Of course it’s missing A LOT yet to really become one (and of course Flash Player 6 was way too slow to do such stuff), but again, with Flash Player 9 and some likeminded developers, this could become quite a blast.

Thanks for listening :)

Addendum: Some good and valid remarks and questions i got in the OSFlash mailinglist:

This is, in my mind, a brilliant idea especially when you throw in Haxe‘s planned ability to render to different (and future) runtimes (I assume that you would use Haxe to do this).

One of the most frequent issues on the Haxe list is the lack of a component written for Haxe. I think that a project like this would solve that issue for Haxe.

I’ve looked into Haxe. It sure looks promising, and It’d be a major plus that a framework written in Haxe potentially wouldn’t have to be tied exclusively to the Flash Player. The first thing i would do if i would start to develop such a framework in Haxe is write a compliant DOM3 Core implementation that works exactly the same in Flash 6, 7, 8 and 9 and in all mainstream browsers. That alone would already kick some serious bottom.

I glanced through the XForms documents on w3c and was wondering if it would be possible to leverage one of the existing component sets (specifically ActionStep or ASWing) to complete this task? To me, it would seem like a much smaller job if we used an existing framework.

But could we imagine to bind a standard Flash XFrames/XForms/CSS parser with any/a few GUI toolkits? That would actually be great, but is it possible to achieve?

I have been asked this question many times already. Theoretically, this is possible. However, if i would develop such a framework, i would surely want to implement CSS3 which features styling and skinning mechanisms that imho beat those implemented in all current GUI toolkits together, and integrates perfectly into all mentioned W3C technologies. So depending on what toolkit you use, you probably can only implement a subset of CSS3. I also think that it wouldn’t be very easy to integrate custom component sets, or rather, i think it wouldn’t be worth the pain.

C64 Emulator for Flash Player 9

I’m happy to finally be able to let the cat out of the bag. Darron Schall and myself have been working on a low level 6502/6510 emulator and, based on that, on a Commodore C64 emulator/simulator.

The emulator is completely written in Actionscript 3 and runs on Flash Player 9. It loads the original binary C64 Kernel ROMs at runtime, and executes them just like the original hardware would do.

The sources are released under GPL, get them here:
Trac: https://mirror1.cvsdude.com/trac/osflash/fc64/
SVN: http://svn1.cvsdude.com/osflash/fc64/

Quoting Darrons blog post from today:

It’s still a work in progress, and we’re looking for hardware-nerds to step up to the plate and help us finish it. The CPU code is complete, but hasn’t been extensively tested. The memory code is a work in progress, and we haven’t had a chance to start on the display code yet. Still though, it’s a good start.

At this point, we’re just running the CPU as fast as possible without trying to get the timing completely accurate. On the debug Flash Player, it runs at ~2.5 MHz. On the release Flash Player, it runs at closer to 6 or 7 MHz. This is a good thing, as the original Commodore chip only runs at 1 MHz. So, in theory, it should be possible to emulate the games in real-time without any slow down or speed delays (holy @#!@).

AS3: Loading Class Libraries at Runtime

The Flash Player 8.5 features a nifty API to dynamically load assets at runtime, using the flash.display.Loader and flash.system.ApplicationDomain classes. Let’s assume we have a package, test.c1, that we want to keep in a separate SWF and only load it into the main SWF when needed.

We create a project Main that has the following structure:

  • Main.as
  • Child1.as
  • test/c1/TestClass.as

Child1.as is compiled into Child1.swf and contains test.c1.TestClass.

Main.as is our main application class that loads Child1.swf and uses test.c1.TestClass.

test/c1/TestClass.as

package test.c1
{
   public class TestClass
   {
      public function TestClass() { }

      public function method():String {
         return 'test.c1.TestClass.method()';
      }
   }
}

Child1.as

package
{
   import flash.display.Sprite;
   import test.c1.TestClass;

   public class Child1 extends Sprite
   {
      public var TestClassInst:TestClass;

      public function Child1() { }
   }
}

Main.as

package
{
   import flash.display.Sprite;
   import flash.display.Loader;
   import flash.system.ApplicationDomain;
   import flash.net.URLRequest;
   import flash.events.*;
   import flash.util.trace;

   public class Main extends Sprite
   {
      private var child1:Loader;
		
      public function Main()
      {
         var url1:URLRequest = new URLRequest('Child1.swf');
         url1.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);

         child1 = new Loader();
         child1.addEventListener(EventType.COMPLETE, onChild1Complete);
         child1.load(url1);
      }

      private function onChild1Complete(e:Event):Void {
         trace('onChild1Complete ' + e);
         var c:Class = child1.loadeeInfo.applicationDomain.getClass('test.c1.TestClass');
         var co:Object = new c();
         trace('test.c1.TestClass.method() returns: ' + co.method());
      }
   }
}

Using this method we could have different implementations of an API in different SWFs, and load the one we need at runtime. Naturally, we would want to use interfaces to ensure the API implements the right things, and use those interfaces for both the external modules and the main app. Note that i instantiate test.c1.TestClass as an anonymous object in the above example (var co:Object = new c();). I actually should have provided an interface definition test.ITestClass that describes the features of that external class (var co:ITestClass = new c();), however the alpha of Flex Builder has a bug that currently prevents us from doing so. Macromedia is aware of that bug so hopefully this is fixed soon.