Canvas

The canvas tag represents the topmost container for all views and elements in an LZX application and there is exactly one canvas for each LZX application. The LzCanvas class is the class that will be instantiated when the LZX compiler encounters the canvas tag. This class is a subclass of LzView.

Table 2.2 lists the attributes defined in the LzCanvas class.

Table 2.2. The attributes defined in the LzCanvas class
NameUsageTypeDefaultAccessibility
buildJS onlystring read-only
 Description. The build number of the LPS that generated this Flash. For .lzo files, this attribute specifies the server that generated the optimized file, not the one that served it.
dataloadtimeoutTag and JSnumber read-only
 Description. The number of milliseconds the application will wait for data loading before it times out.
datasetsJS only  read-only
 Description. The dictionary of all named datasets in this application.
debugTag and JSbooleanfalseread-write
 Description. Indicates if debugging is enabled. The Debug window will be displayed if debugging is enabled.
embedfontsTag and JSbooleantrueread-write
 Description. Indicates if the fonts used in this application should be embedded.
expiresJS onlystring read-only
 Description. The expiration date of this application.
librariesTag and JSstring read-write
 Description. A list of names of libraries included in this application.
lpsreleaseJS onlystring read-only
 Description. The release number of the LPS that generated this application. For .lzo files, this is the release number of the server that generated the optimized the file, not the one serving it.
lpsversionJS onlystring read-only
 Description. The version number of the LPS that generated this application. For lzo files, it is the version number of the server that generated the optimized file, not the one serving it.
maxtextheightTag and JSnumber read-write
 Description. The maximum height of any output text field in pixels.
maxtextwidthTag and JSnumber read-write
 Description. The maximum width of any output text field in pixels.
medialoadtimeoutTag and JSnumber read-only
 Description. The number of milliseconds the application will wait the media loading operation before it times out.
onpercentcreatedJS only  read-only
 Description. Invoked when the number of created nodes changes.
percentcreatedJS only  read-only
 Description. A number between 0 and 1 (inclusive) that represents the percentage of the application that has been instantiated.
proxiedTag and JSboolean read-only
 Description. Indicates whether or not runtime requests should be proxied.
titleTag and JSstringLaszlo Applicationread-write
 Description. The title of the browser that plays the generated Flash.
validateTag and JSbooleantrueread-write
 Description. Indicates if the application source will be validated against the schema during compilation.
versionTag and JSstring read-only
 Description. The version for this LZX application.

The following are methods defined in the LzCanvas class:

compareVersion(version, anotherVersion)

Compares two version strings. It returns -1 if the version argument is less than anotherVersion, 0 if version is equal to anotherVersion, and 1 if version is larger than anotherVersion.

setContextMenu(cMenu)

Sets cMenu as the right click menu for the canvas.

setDefaultContextMenu(cMenu)

Sets cMenu as the right click menu on the canvas and the default menu for all views.

For example, the code in Listing 2.5 shows how to use the canvas tag and some of its attributes.

Listing 2.5. Using the canvas tag
<canvas title="Testing Canvas" width="300" height="200"
        bgcolor="#ddddee">
    <text>OpenLaszlo is cool.</text>
</canvas>

You can use a double quote or a single quote to enclose an attribute value. However, for consistency, the double quote will be used throughout this book.

You can compile and run the code in Listing 2.5 by using this URL:

http://localhost:8080/lps-4.0.x/app02/canvasTest1.lzx

The result is shown in Figure 2.5.

Figure 2.5. Using canvas


Note that the canvas tag in Listing 2.5 specifies the string “Testing Canvas” as the value of its title attribute. This value is displayed as the browser title.

The background of the HTML page follows the canvas background color. As such, the right border is not visible here. However, if you reduce the width to 100, you will see the text truncated.

If the width is not specified, the generated output will occupy the whole width of the browser. If the height attribute is not present, the generated output will fill the whole height of the browser.

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

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