[Laszlo-user] Appreciation for OL and an important code snippet to share for christmas
James Robey
circlecycle at gmail.com
Wed Dec 10 01:49:41 PST 2008
I just wanted to take the time out of a busy coding schedule to tell
the list (and all of the people subscribed but not active posters)
just how much i like, appreciate, and use the Open Laszlo framework
day to day. It is a joy to use, a joy to discuss, and a pleasure to
earn a living with. Thank you, all that have ever been involved, in
producing something of such abstractional purity, of such clarity and
ease, that it has changed and refocused my coding life.
Thanks to all of You, who make this open-source project the success it
is.
Sincerely,
James Robey.
p.s. i am releasing, for those in the know and not afraid to ponder a
short code segment, something called "waypoints" for the OL language.
It allows you to manipulate/access deeply nested view hierarchies with
NONE of the usual headaches. I hope that this will be of use to the
whole community. The extremely short code and explanation is attached
as a text file. To me, it is a addition and celebration of the magic
we have to play with here, and of constant utility to my everyday
work. Thanks for reading and Merry Christmas!
(waypoints.lzx attached and reproduced below)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: waypoint.lzx
Type: application/x-lzx
Size: 3381 bytes
Desc: not available
Url : http://www.openlaszlo.org/pipermail/laszlo-user/attachments/20081210/454c850e/waypoint-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: waypoint.swf
Type: application/octet-stream
Size: 77882 bytes
Desc: not available
Url : http://www.openlaszlo.org/pipermail/laszlo-user/attachments/20081210/454c850e/waypoint-0001.obj
-------------- next part --------------
----------------------------------------------------------------------------------------------------------------------------------
<canvas width="500" height="500" bgcolor="yellow">
<!-- The waypoint class allows for "deep" navigation of nested
namespaces -->
<class name="waypoint" extends="node" initstage="early">
<!-- if this atttribute is specified, then the waypoint will be
added at that node -->
<attribute name="at" type="expression"/>
<!-- if this attribute is specified, then a waypoint by this name
will be added to the waypoint parent -->
<attribute name="named" type="string"/>
<!-- at construct time, determine the waypoint parent and add
references, as/if needed -->
<method name="construct" args="p, a">
//retrieve values from the tag
var at = a['at'];
var named = a['named']
var np = at ? eval(at) : p.parent;
//find out which node will receive the new waypoint
while(1){
//have we found a potential parent waypoint or have an "at"
operation (waypoint explicitly on)?
if(at || np['_'] || np['id'] || np.nodeLevel == 0){
//initialize space ('_') to hold waypoints if this is a
new waypoint parent.
if(np['_'] == undefined) np._ = {};
//if no name given make a name based on the number of
other nameless waypoints
//otherwise ensure the name doesn't overwrite anything
in the target waypoint space.
if(!named){
// if __waypointCount is not defined initialize it
to zero, otherwise increment
np.__waypointcount = np['__waypointcount'] !=
undefined ? np.__waypointcount + 1 : 0;
// and use value that to generate a unique name
named = "__waypoint"+np.__waypointcount;
}else if(np._[named] != undefined){
Debug.warn('waypoint overwritten:', np, 'name',
named);
}
//Add this node to a waypoint parent, add the waypoint
to this node ("parent"), then break
np._[named] = p;
if(!p['_'])
p._ = new Object;
//record the parent waypoint to this tag
p._.parent = np;
break;
}
//...or just keep looking up the tree until we find a good
target.
np = np.parent;
}
//we don't need the this anymore, it's done it's job (cyclic
GC? investigate)
super.construct();
</method>
</class>
<!-- test of the waypoint utility. Note that we can set the
innermost color in the init handler
regardless of how many enclosing <view>'s the tag is in! No
'useless' names to change when you wrap
a view to get some visual effect or another. No globals!
-->
<simplelayout axis="y"/>
<view name="topview">
<waypoint/>
<view width="100" height="100" bgcolor="blue">
<view width="50" height="50" bgcolor="green">
<view width="25" height="25" bgcolor="red">
<waypoint named="test"/>
</view>
</view>
</view>
</view>
<view width="100" height="100" bgcolor="black">
<text fgcolor="white" text="click me"/>
<handler name="onclick">
canvas.topview._.test.setAttribute('bgcolor', '0xffffff');
</handler>
</view>
</canvas>
More information about the Laszlo-user
mailing list