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.

Tab Completion in the Debugger

There’s a handy tab completion feature in the OpenLaszlo debugger now. It’s been around for a few months, but I’ve avoided using it mainly because the keyboard focus was a little flaky on my old Windows laptop.

It works just like a typical Unix (say bash) shell:

  1. Recompile your application with the debugger. e.g. browse to the Hello, World! example with ?debug=true.
  2. Click on the Debugger text input field, and begin typing. e.g. can
  3. Hit tab. The Debugger should complete the word “canvas”.
  4. Now add a dot, and hit tab once. e.g. canvas.
  5. If there are too many possible matches, you’ll see output like the following in the Debugger:
    INFO: 456 possibilities: press ‘\t’ again to see them all
  6. Hit tab again, and you should see a long list of possible properties on canvas:
    INFO: Possible completions: $cfn $isstate $lzc$bind_id $lzc$bind_name …
  7. Now add “sub” to the text input field. It should read canvas.sub
  8. Hit tab. You should see two possible matches for canvas.sub:
    Possible completions: subnodes subviews
  9. Add a “v”, so your text input field now says canvas.subv
  10. Hit tab. The debugger should complete that to canvas.subviews, since its the only possible match. Now hit the enter key, and the Debugger will inspect canvas.subviews.

Enjoy!

The lz Namespace

I wrote about migrating code to OpenLaszlo 4.1 a while back, but even after a few weeks of working with it, I’m still getting bitten by the new lz namespace. I’m just so used to doing things the old way, and this (pretty significant change) is not that well documented, and . Here’s a summary of the lz namespace, and how it affects LZX code.

Firstly, a general rule: These changes apply to referencing classes in JavaScript and JavaScript expressions in attribute values or constraints only. The way you write tags is unchanged.

For classes that have a corresponding tag, the new syntax is to use lz.classname. (Note: all lower case, for LFC classes). This applies to Laszlo Foundation Classes (e.g. view, text), LZX components (e.g. button, window) and all classes that you write. These now live in the new lz namespace:

// Old pre-4.1 syntax
var v = new LzView(canvas, {width: 30, height: 30, bgcolor: red});

// New 4.1 syntax
var v = new lz.view(canvas, {width: 30, height: 30, bgcolor: red});

For classes with no tag, (e.g. LzDelegate, LzContextMenu), the syntax is unchanged, so you would use LzClassName. These continue to live in the global namespace:

// Old pre-4.1 syntax
var v = new LzDelegate(this, "doSomething", this, "onmouseover");

// New 4.1 syntax (unchanged)
var v = new LzDelegate(this, "doSomething", this, "onmouseover");

For services (e.g. LzKeys, LzTimer), there has been some refactoring. The class names are now called LzKeysService, LzTimerService, and they are accessible by the new syntax lz.Name (note there’s no “Service” suffix to the name).  They are in the lz namespace:

<!-- Old pre-4.1 syntax -->
<handler name="onkeydown" reference="LzKeys" args="keyCode">
    Debug.write("User pressed key: ", keyCode);
</handler>

<!-- New 4.1 syntax -->
<handler name="onkeydown" reference="lz.Keys" args="keyCode">
    Debug.write("User pressed key: ", keyCode);
</handler>

JavaScript classes (e.g. String, Math) are unchanged. They’re not technically part of the LZX global namespace.

// Old pre-4.1 syntax
var opposite = hypotenuse * Math.sin(angle);

// New 4.1 syntax (unchanged)
var opposite = hypotenuse * Math.sin(angle);

These four categories should cover all the possible scenarios you have to deal with as a developer. If you’re ever in doubt, or want to explore what’s in the namespaces, enter lz or global in the Debugger window and click Eval. Then click the blue link that the Debugger returns to serialize the object. You’ll be able to see all the class names and objects that are in each scope. Once this is done it is only a matter of putting it online on your site, and it should work just fine, great even. Remember however, that for it to have any effect you will need traffic, so you’ll want to make sure you work with experts to have a good SEO score. Here you can learn more about franchise SEO services if you would like to research the topic further. Make sure that you do this sooner rather later so that you can see the effects as soon as possible and get the project rolling!