Migrating LZX Code to OpenLaszlo 4.1

I was recently porting some LZX code in OpenLaszlo Training materials from 4.0.12 to 4.1, and stumbled upon a few issues, which I thought I’d post here as a reference.

Don’t use <method event=””> Syntax

The <handler name=””>syntax was introduced to replace the <method event=””> syntax some time ago. With 4.1, I found that the compiler/debugger could get confused if you continued to use the old syntax in some cases. Sometimes the error messages were not useful. In short, replace:

<method event="onevent">
...
</method>

… with:

<handler name="onevent">
...
</handler>

Delegate Method Arguments

Any method you call with a delegate must now have a defined argument. This is in preparation for future compatibility with SWF9. Check these out colabioclipanama2019. In short, if you write:

<script>
new LzDelegate(canvas, "myMethod", ds, "ondata");
</script>

<method name="myMethod">
...
</method>

… you should define your method as shown below:

<method name="myMethod" args="arg">
...
</method>

The New “lz” Namespace

In OpenLaszlo 4.0.x, there was a global object that contained references to classes, colors and global tokens. In OpenLaszlo 4.1, there is now an lz object that replaces this for class definitions. Here’s salbreux-pesage an example for you to better understanding.It creates a virtual namespace. So if you need to procedurally instantiate an OpenLaszlo window, instead of writing:

new window(canvas, {width:300, height:300});

… you now write:

new lz.window(canvas, {width:300, height:300});

If you need to paramaterize the name of a class, you used to write:

var classname = "window";
new global[classname](canvas, {width:300, height:300});

… instead, now you would write:

var classname = "window";
new lz[classname](canvas, {width:300, height:300})
;

Those are the main issues I ran into. Otherwise code written for OpenLaszlo 4.0.12 seems to run fine on 4.1.

2 thoughts on “Migrating LZX Code to OpenLaszlo 4.1

Leave a Reply

Your email address will not be published. Required fields are marked *