[Laszlo-user] Quickie link callback

Maynard Demmon mdemmon at laszlosystems.com
Mon Jun 4 16:16:39 PDT 2007


Here is a little piece of laszlo code you might find usefull. It lets
you do an easy callback to your lzx app when a user clicks on a link
defined in a <text> component. Note that the syntax of
Lz.setCanvasAttribute is in the 4.x not the 3.x format of this call.

	var msg1 = "<a
href=\"javascript:Lz.setCanvasAttribute('linkcallback','action1:value')\
">do action 1</a>";
	var msg2 = "<a
href=\"javascript:Lz.setCanvasAttribute('linkcallback','action2:value')\
">do action 2</a>";
	myTextComponent.setText("stuff" + msg1 + "other stuff" + msg2 +
"event more stuff");

Code in main.lzx to handle the linkcallback action would look something
like this:

	<!-- ATTRIBUTES -->
	<attribute name="linkcallback"/>
	
	<!-- EVENT HANDLERS -->
	<method event="onlinkcallback" args="v">
		var index = v.indexOf(":");
		var type = v.substring(0, index);
		var value = v.substring(index + 1);
		switch (type) {
			case "action1":
				// do something
				break;
			
			case "action2":
				// do something
				break;
			
			// More cases for additional actions as needed
		}
	</method>
			
Maynard Demmon - mdemmon at laszlosystems.com
Senior Developer - Laszlo Systems




More information about the Laszlo-user mailing list