Tips and Tricks
From OpenLaszlo
Contents |
Command-Line Debugging
If you are debugging and you want to call lzc directly, and you want to see log messages for just a few specific classes in the console, you can do that, like so:
Create a file named $LPS_HOME/console- debug.properties containing something like this:
log4j.logger.org.openlaszlo.compiler.CanvasCompiler=DEBUG
that is:
log4j.logger.<package or class name>=<loglevel>
In your source code, create a logger for that class, or use the existing logger. CanvasCompiler.java declares:
private static Logger mLogger = Logger.getLogger(CanvasCompiler.class);
Then call methods on mLogger: debug, info, error, warn
mLogger.debug("(debug) Compiling canvas.");
mLogger.info("(info) Compiling canvas.");
mLogger.error("(error) Compiling canvas.");
Then invoke the compiler with -lp console-debug.properties:
lzc -lp console-debug.properties test/hello.lzx
...and you'll see log messages for the level you specified and higher, for that class or package only.
Developing and Debugging SWF10 Programs
If you are developing an app for the SWF10 runtime, it can be useful to have the Flash Debug Player installed. This can be downloaded from the adobe web site [1] and [2]
You can use the Flex command line debugger to debug your Laszlo app while it runs in the browser. To do this, invoke your app from fdb using
fdb "http://127.0.0.1:8080/lps/your/app/path.lzx?lzr=swf10"
The app will load into the browser, and then the fdb console will pause so you can set breakpoints if you wish. Type "C" to continue.
badtzmaru:trunk6 hqm$ fdb "http://127.0.0.1:8080/trunk6/test/smoke/mixin-simple.lzx?lzr=swf10" Adobe fdb (Flash Player Debugger) [build 0] Copyright (c) 2004-2007 Adobe, Inc. All rights reserved. Attempting to launch and connect to Player using URL http://127.0.0.1:8080/trunk6/test/smoke/mixin-simple.lzx?lzr=swf10 Player connected; session starting. Set breakpoints and then type 'continue' to resume the session. [SWF] /trunk6/test/smoke/mixin-simple.lzx - 1,663,924 bytes after decompression (fdb) c Additional ActionScript code has been loaded from a SWF or a frame. To see all currently loaded files, type 'info files'. Set additional breakpoints as desired, and then type 'continue'. (fdb) c [SWF] /trunk6/test/smoke/mixin-simple.lzx - 357 bytes after decompression [SWF] /trunk6/test/smoke/mixin-simple.lzx - 345 bytes after decompression ...
Flex 4 SDK Info and Documentation
OpenLaszlo currently ships with a copy of the Flex 4 Compiler SDK (Adobe's code name is Gumbo), specifically the last 'stable build', which is flex_sdk_4.0.0.6898 May 14
I am not sure which Adobe documentation web page corresponds most closely to this flex build. They are up to a Flex 4 Beta 2 release now, but I don't know how much the API differs from the milestone build we're using.
I've been using this URL for documentation of the Flex SDK http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/index.html?filter_flex=4
Using Actionscript 3 code in a SWF10 Application
There are several ways to get actionscript 3 runtime-specific code into an OpenLaszlo application.
If you are writing AS3-specific code, it is very important to understand how OpenLaszlo code is converted into actionscript 3. In AS3, generally every block of code must belong to an AS3 class and package.
The OpenLaszlo compiler parses your application and generates a set of intermediate as3 class files.
If you need to access some Flex4 classes in your code, you will need to add as3 "import" statements for each class. You can do that inside of an LZX class with the <passthrough> tag. For example, see the lps/components/incubator/uploader/fileupload.lzx example
<library> <class name="fileupload">
<switch>
<when property="$as3">
<passthrough>
import flash.events.*;
import flash.net.*;
</passthrough>
</when>
</switch>
This is a cross-(Flash)-runtime portable class definition that has the correct import statements for as3.
Declaring AS3 code in script
If you are writing your classes in straight "javascript", you would do something like this. Note that "when=immediate" is required for the script tag, so that it inserts the code block at the top level.
<script when="immediate"><
