Your First OpenLaszlo Application

The steps for developing an OpenLaszlo application are as follows.

1.
Write your OpenLaszlo program (in XML and JavaScript) using a text editor.

2.
Save the file as an lzx file.

3.
Compile the lzx file to an swf file or DHTML, either manually or by using the OpenLaszlo server.

You can then run the output in a Web browser.

The steps are described in the following subsections.

Writing an OpenLaszlo Application

As mentioned before, an OpenLaszlo application is an XML document. Therefore, you can use any text editor to write your code. The code in Listing 1.1 is a simple LZX application.

Listing 1.1. A simple example
<canvas height="150" width="200" bgcolor="yellow" >
    <view width="150" height="100" bgcolor="white">
        <button text="OpenLaszlo"
                onclick="setAttribute('text', 'rocks')"/>
    </view>
</canvas>

Saving the Source File

Now, save the script as the firstLaszlo.lzx file. The file must be saved in the Server/lps-4.0.x directory under the OpenLaszlo Server installation directory or a directory under it. If you have downloaded the zip file that contains sample applications for this book and extracted them as explained in Introduction, you already have subdirectories under the Server/1ps-4.0.x directory. You can find the firstLaszlo.lzx file under the app01 subdirectory.

Compiling and Running the Script

The easiest way to compile an lzx file is by using the OpenLaszlo Server. Make sure that Tomcat is running on your computer, and then direct your browser to the following URL:

http://localhost:8080/lps-4.0.x/path

Here, path is the path to the lzx file relative to the Server/lps-4.0.x directory under the OpenLaszlo Server installation directory. For example, if your script is saved as the firstLaszlo.lzx file under the app01 directory under Server/lps-4.0.x directory, you use this URL to compile your OpenLaszlo application.

http://localhost:8080/lps-4.0.x/app01/firstLaszlo.lzx

The servlet container will pass your HTTP request to the OpenLaszlo Server. The latter opens and compiles the correct lzx file, generates the output, and saves it in a temporary directory. The OpenLaszlo Server then sends the generated output to the browser.

If the application is compiled as Flash, the generated swf file and related files are cached, so subsequent requests for the same unmodified lzx file will be much faster because no recompilation needs to be performed. If the compilation failed, an error message will be displayed on the browser.

For this OpenLaszlo application, you will see a Flash application displayed in your browser, as shown in Figure 1.2.

Figure 1.2. Your first OpenLaszlo program


There are two parts in the browser window. The top part is the output of your application. There is a button that says “OpenLaszlo” on top of a white rectangle, placed inside a bigger yellow rectangle. If you click the button, the text on it will change to “rocks.”

The bottom part is a development tool containing buttons that allow you to view your OpenLaszlo source code, deploy your application, recompile the source code, and perform other functions. There is also some information at the bottom of Figure 1.2 that says that the runtime target is Flash 7 and the size of the Flash file is 88,984 bytes.

To save space, the bottom part will not be shown for other applications in this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset