Saturday, May 24, 2008

DHTML/SWF Differences in OpenLaszlo

OpenLaszlo is well known for supporting the ability to compile the same source code into either Flash Player-ready code (SWF) or into dynamic HTML (DHTML). While significant amounts of code can be written in OpenLaszlo's LZX and JavaScript subset languages that does compile to both runtime platforms, there are certain APIs and libraries that are specific to one runtime or the other.

In this blog entry, I attempt to collect some of these differences for easy future reference. Note that this is a collection based on what the OpenLaszlo documentation says, what others' blogs and articles say, and what I have found in my own OpenLaszlo development. The reason to note this is that things may and probably will change and some things may have already changed since the sources I have used were originally written.

Before diving into the list of items in OpenLaszlo that are specific to either DHTML or to SWF, it is also important to note that, as of this writing, the two production-ready runtime environments for OpenLaszlo appear to be Flash 7 (SWF7) and Flash 8 (SWF8). While OpenLaszlo's DHTML runtime support already covers significant functionality, the OpenLaszlo 4.0.12 Release Notes (currently the latest stable version) states that DHTML support is still in "beta" and that it will move out of beta with the release of OpenLaszlo 4.1. As I blogged about earlier, the 4.1 release will likely be delayed because of renewed emphasis on finishing OpenLaszlo's support for Flash Player 9.

Different Runtime Environment Support

The most obvious differences between OpenLaszlo SWF and DHTML support may be in the classes OpenLaszlo expressly provides for the different runtimes. The advantage of using these runtimes is that doing so is largely transparent to the developer. The three classes are LzBrowser (mentioned in a previous blog entry), LzKeys, and LzHistory. These unique and different versions of the same three classes for the different runtimes appears to be an OpenLaszlo 4.1 feature.


Chapter 8 ("Introduction to Media and Art Assets") of the OpenLaszlo Application Developer's Guide has a specific section on Runtime Considerations that warns that SWF assets cannot be used in DHTML applications and that formats not available in the Flash runtime are obviously not available to DHTML applications hosted in SOLO mode.

Chapter 18 ("Media Resources") of the OpenLaszlo Application Developer's Guide points out that more image types can be loaded by the Flash Player 8 than by Flash Player 7 in the section Flash 7 and Flash 8 Limitations (applies to SOLO deployments).

Chapter 21 ("Text Views") of the OpenLaszlo Application Developer's Guide reminds the reader that only image formats supported by the Flash Player can be used in an OpenLaszlo application intended for the Flash Player as at least one of its target runtimes.

All of the discussion in Chapter 42 ("Audio and Video") of the OpenLaszlo Application Developer's Guide is devoted to Flash-only runtime.

Text and Fonts

Chapter 9 ("Introduction to Text and Fonts") of the OpenLaszlo Application Developer's Guide also warns about potential use of things (text fonts in this case) that are specific to one runtime or the other. Chapter 23 ("Fonts") of this same document provides greater detail on the SWF-specific font support that is available as well as the difference in rendering of DHTML applications as opposed to SWF applications. An example of differences between the two runtimes' handling is the availability of embedded fonts in Flash runtimes (albeit with larger downloads) that are not available for DHTML (client or system fonts are the only ones available there). The implication of this is that consistency of font appearance cannot be guaranteed for DHTML applications like it can be for SWF if embedded fonts are used in the Flash Player.

Chapter 22 ("Rich Text") of the OpenLaszlo Application Developer's Guide covers the richinputtext LZX tag and states that this is for Flash runtime only.

Browser Integration

Whether compiling one's OpenLaszlo application to Flash (SWF7 or SWF8 as of now) or to DHTML, it is almost certain that the deployed application will be run in a web browser. Chapter 35 ("Browser Integration") of the OpenLaszlo Application Developer's Guide points out differences in browser integration for Flash runtimes versus DHTML runtime. The section Applications Compiled to SWF points out that LzBrowser allows the OpenLaszlo-generated SWF to be visible to the hosting browser's JavaScript and the setCanvasAttribute can be used for the OpenLaszlo application to access hosting JavaScript. For DHTML, as documented in the section Applications Compiled to DHTML, the OpenLaszlo application is an object in the browser's DOM and therefore can directly access and be accessed by that Document Object Model.

Miscellaneous Differences

There are some less significant differences between OpenLaszlo applications compiled to DHTML and those compiled to Flash such as differences in recommended debugging tools (general web development tools useful for DHTML are not useful for Flash in most cases). Perhaps the most common difference I run into when compiling to these different runtimes is in the appearance detail. Often, my OpenLaszlo applications work in both DHTML and Flash at a minimum level, but the appearance can differ greatly between the Flash runtime and the DHTML runtime. While the application does technically "work," the statement the devil is in the details truly applies because it can take a lot of iterative trial-and-error to get layouts, fonts, and other presentation aspects set just right to appear correctly in Flash and in the major browsers' DHTML rendering.

What Does This All Mean?

I have referenced the OpenLaszlo Application Developer's Guide repeatedly in this blog entry because that seems to be the best source of details on which aspects of OpenLaszlo work only in DHTML or only in SWF. A particularly useful overview of the DHTML versus Flash runtime decision also comes from this same document. Chapter 2 ("Language Preliminaries") of this document contains a section called On Runtimes and Deployment Modes and the 'Core' API. This section points out the four major choices an OpenLaszlo developer can make when considering runtimes. Before OpenLaszlo 4 (and really until OpenLaszlo 4.1 is available with DHTML support out of beta), Flash is the safest bet for production runtime and having a Flash-only solution (ensuring no DHTML-only code in the application and leveraging some features provided by the Flash Player) is likely a popular option. On the other hand, if a particular user set does not have access to the Flash Player or the developer has other concerns about the Flash Player, he or she may choose the DHTML-only solution (do not use any Flash-specific features or code and do take advantage of some DHTML-specific features). The developer who wants the freedom to switch between runtimes easily will choose to either use only the "core" APIs that don't have features specific to either runtime or will choose the last option, which is to write the code to conditionally use specific features only when in that particular runtime. An example of this last option, conditionally compiling depending on the runtime, is discussed in the OpenLaszlo Application Developer's Guide in Chapter 49 ("Understanding Compilation") in the section Conditional Compilation of Runtime-Dependent Code.


For the most part OpenLaszlo code can be compiled into either Flash or DHTML runtimes and it is likely that the DHTML support that is now in beta will be much better with the OpenLaszlo 4.1 release. While I currently prefer OpenLaszlo's Flash runtime support, it is an advantage knowing that all or significant portions of my OpenLaszlo applications can likely be readily compiled to DHTML should a situation arise in which use of the Flash Player by clients, customers, and other users is not practical.

No comments: