PASZ.COM LABS

Monday, November 14, 2005

The haXe Programming Language

Nicolas Cannasse, the mastermind behind MTASC, has a new project in the works. HaXe is not ready for prime time, but I expect he's going to deliver something impressive. It would be great to be able to write code for old and new flash players alike without having to worry about the transition from AS 2 to AS3. A quick glance at the reference page suggests that the language is already quite a bit like ActionScript.

Key quote for AJAX developers:
Writing small Javascript applications takes time. Mainly because unless you are familiar with DHTML API and Browser differences, you need a lot of tests to make it work correctly. On another point, scaling medium and large Javascript applications is also difficult because of the lack of ways to structure your application (using classes for instance).

haXe ...brings you the whole DHTML API and give you a type system to check that you're using them correctly. Some features of the type system are especialy designed to play nice with the inheritent dynamic typing of DHTML. You can also use classes to structure your program, and easily interact with haXe code running in Flash and on the server side.

The haXe compiler is generating some valid Javascript source code from several haXe classes and files, so you only have to generate one time and then include the .js as usual in your webpage.

Since it doesn't seem like browser manufacturers are ever going to be on the same page, javascript "compilers" like haXe may be the wave of the future.

Sunday, November 13, 2005

Fun with External Interface

So I finally had some time to start playing around with Flash 8. Here's a demo I built that shows the potential power of the ExternalInterface feature. One of the limitations of Flash has always been that the developer is "boxed into" the flash area of the page. There have always been tools to work around this problem, but ExternalInterface makes things so much easier because you can call ActionScript functions directly from JavaScript, and even pass parameters.

My demo sets up a mouseMove event handler, and passes the current x,y coordinates into Flash. Flash, in turn, uses the coordinates to adjust the rotation of the arrow clip so it's always pointing at the cursor. I was impressed by how smooth the animation is, which suggests that communications via ExternalInterface are very fast. (It would be interesting to do a comparison using "old school "data exchange techniques like SetVariable.)

There are a couple of limitations in the current demo. First of all, when you actually move the cursor into the flash area, callbacks stop working. Also, the movement of the arrow is restricted to a 90 degree slice. It would take some additional calculation to create 360 degrees of rotation.

I'll try to post the code later this week.

Credits
There's a nice tutorial on actionscript.com that helped me figure out how to set up a callback to ActionScript.
Codelifter.com has good (if slightly dated) code for determining the x-y position in JavaScript.
Finally, the original inspiration for this project came from reading Chapter 3 of Foundation Actionscript Animation by Keith Peters.