OpenLaszlo 4.2 adds SWF9 Support

In case you missed it among the holiday cheer, OpenLaszlo 4.2 was officially released last week. Personally, I’ve been looking forward to this release for a while, since it adds support for SWF9. SWF9 is bytecode that’s optimized for the Flash Player 9 runtime. Flash developers may know it as ActionScript 3 (AS3). The exciting thing for OpenLaszlo developers is that SWF9 is vastly faster than SWF8. And since Flash Player 9 is widely-deployed, you can start using it as the default runtime for new applications.

SWF9 support may not sound like a huge deal to many people – it’s just a matter of keeping up-to date with the newer version of Flash, isn’t it? Well, not exactly. The difference between SWF8 bytecode and SWF9 bytecode was significant. So big, in fact, that Adobe included two completely separate runtimes in Flash Player 9: one for running the new SWF9 bytecode, and a separate one for running SWF8-and-below bytecode. In other words, the SWF9 capability is a pretty big deal.

Just how much of a performance gain does the new runtime offer? A few months ago, while writing a post about optimizing data for Lzx (OpenLaszlo Performance Tip: Attributes, not Nodes), I found that the then-beta SWF9 runtime in OpenLaszlo was as much as 3.7 times faster than the SWF8 one, at loading and parsing XML data. At the time, much of the functionality was still missing from the 4.2 branch, so data loading was the only behavior I could test.

With 4.2 available, I wrote a simple test that measured how long it took to instantiate 100 windows:

<canvas>

    <text id="output" fontsize="36" />

    <class name="mywindow" extends="window" width="300" height="200">
    </class>


    <handler name="oninit"><!&#91;CDATA&#91;
        var dStart = new Date();
        var j:Number = 0;
        var xpos:Number;
        var ypos:Number;

        for (j=0; j<100; j++) {
            xpos = Math.max(150, Math.random() * canvas.width);
            ypos = Math.max(50, Math.random() * canvas.height);
            new lz.mywindow(canvas, {x: xpos, y: ypos});
        }
        var dEnd = new Date();
        var timeTaken = dEnd.getTime() - dStart.getTime();
        output.setAttribute("text", timeTaken);
        &#93;&#93;>
    </handler>
    
</canvas>

The results for creating 100 windows in OpenLaszlo 4.2.0 are:

  • SWF8: 6,042ms
  • SWF9: 1,073ms

That’s 5.6 times faster – even more dramatic than the results from the data loading test!

Surely all OpenLaszlo developers will now rush to recompile their applications to SWF9; all it takes is appending ?lzt=swf9 to the request, doesn’t it? Unfortunately, it’s not that simple. Moving from OpenLaszlo 4.0 to 4.1 involved a lot of language changes, specifically in anticipation of SWF9. I wrote about this a while back. Then, moving from OpenLaszlo 4.1 to 4.2, there were a few more changes, mainly because icompatibilities were found after 4.1 had been released, and in-depth development had started on supporting the new runtime. As an example, the <script> tag shouldn’t be used in SWF9. It actually partly works, but causes confusing errors. Better replace it with <handler name=”oninit”>.

Happily there are some resources and tools for developers needing to migrate their applications. There’s an OpenLaszlo wiki page on Runtime Differences, which should be your first stop. It describes how to use the Perl migration script that (in theory) updates your code for you. Remember that it may not catch everything. It’s hard to anticipate every manner in which developers will use a platform, so please be patient and provide any feedback on issues you hit on the forums or mailing lists.

Changes at Google Maps

The good folks at Google Maps appear to have been busy. The UI for the zoom/pan control (GLargeMapControl) has been refreshed with a new skin. The process for selecting the position from which to view the neigborhood using the Street View feature is simplified – the draggable “person” is always present in the zoom control.

New Google Maps Interface
New Google Maps Interface

The entire Street View feature is now a Flash-based application, that takes over the map screen. Previously, the street panorama would be displayed in a Google Maps info window, and was implemented in DHTML.

The satellite imagery has also been replaced with higher-resolution pictures from the GeoEye Satellite, which was launched a couple of months ago. At least that’s the case in my neigborhood, and a couple of other spots I searched in California.

Even the Street View images have been updated – again, at least in my neigborhood. Check these out elizabethnelsonstudio .

Although the new zoom/pan control does not appear to be available to developers using the Google Maps API, the new satellite images are present by default. Hopefully this means that we’ll finally have a globally-consistent maximum zoom level!

The id Attribute in 4.1

One subtle thing that has changed in OpenLaszlo 4.1 is that you can no longer specify the id attribute when instantiating objects from script.

When instantiating a class from script, you can specify a dictionary of initial properties as the second argument to the constructor:

var v = new lz.view(canvas, {width: 300, height: 300, bgcolor: 0xff0000}); // 4.1

Prior to OpenLaszlo 4.1, the constructor shown above would have been LzView() instead of lz.view(). Also, prior to 4.1, you could have specified the id attribute in addition to the width, height, and bgcolor attributes, and then referenced your newly-created view by that id later in the application. e.g.

var v = new LzView(canvas, {id: "myNewView", width: 300, height: 300, bgcolor: 0xff0000}); // 4.0.12

Since the SWF9 does not allow global variables to be created on-the-fly, OpenLaszlo 4.1 will no longer allow you to do this either. For better or for worse.