Testing Properties

In LZX, it’s often sensible to test JavaScript properties before using them, to be sure that they are defined, e.g.

// Bad example
if (someObject.someValue) {
setAttribute("x", someObject.someValue);
} else {
var defaultValue = 123;
setAttribute("x", defaultValue);
}

In the above example, if someObject.someValue were undefined, then the conditional test would fail and the default value would be used.  Here rothwelldouglas you can check other basic examples of testing properties. However there are a couple of problems in the above code. For more examples must check songsforromance .

Firstly, if someValue is undefined, referencing it with a dot syntax (i.e. someObject.someValue) will throw a Debugger warning that reads “reference to undefined property “someValue”). You don’t want to have lots of debugger warnings in your application. Your application will run more slowly as the Debugger generates the warnings (only with the debugger open, though), and you might miss important warnings in the noise. To get more information visit elizabethnelsonstudio .

Secondly, if someValue is actually defined as something that will equate to false in a conditional, then the conditional will fail. In the above example, if someValue was the number 0 (zero), the conditional test would fail, since in the Flash runtime the number 0 converts to a boolean false. (See this handy O’Reilly article on Data Type Conversion in Flash).

A better way to test the above variable before using it would be:

if (someObject["someValue"] != undefined) {
setAttribute("x", someObject.someValue);
} else {
var defaultValue = 123;
setAttribute("x", defaultValue);

For more examples visit at topquartile .

scriptlimits Attribute

OpenLaszlo 4.0.10 (released yesterday) includes the new scriptlimits attribute of canvas, which allows developers override Flash’s default script timeout and recursion settings.  I wrote about how to change these limits manually a while ago, and this has now been turned into a feature of OpenLaszlo.

The syntax is as follows:

<canvas scriptlimits=”timeout: 300; recursion: 65535″>

</canvas>

You should avoid setting the limits high to avoid the scrip-running-slowly error on poorly-performing applications. Instead reduce the limits when testing your application, to surface performance problems sooner on faster machines. Fix the root causes of poor performance, then increase the limits for deployment.

Latest OpenLaszlo Reference

If you’re not already using it, I’d highly recommend you start using the nightly builds of the OpenLaszlo Reference. You can either download a nightly build of OpenLaszlo that contains it, or use the hosted live copy. Unless you really need to read it offline, use the hosted version.

This trunk version of the reference looks similar to the old OpenLaszlo 3.x reference, but the doc generation tools have been rewritten from scratch, and the standards have been revised. It’s more accurate, more events are listed, the appearance is cleaner and the categories have been simplified. Here’s how the new attribute categories work:

  • initialize-only: You can only set this attribute once, when initializing the object. It doesn’t matter if you use a tag or script to initialize the object. e.g. name, id.
  • read-write: This is an attribute that you can change at run-time (via a setter method or the generic setAttribute() setter method, or a constraint). e.g. x, width.
  • readonly: You can not set this attribute at init time (either in a tag or in script), but you can read it using JavaScript (using dot-syntax), or inside a constraint. e.g. framesloadratio, totalframes.

Note that if you download OL 4.0.9.1 (the current stable version), you won’t get the latest reference; instead you’ll get the old 4.0 one, that’s worse than the 3.x version.