[Laszlo-dev] lz.tagname -- requesting review

John Sundman jsundman at laszlosystems.com
Mon Jan 29 10:25:11 PST 2007


Tucker,

Would you kindly review the following paragaphs & emend as necessary?

Thanks,

jrs

<p>The following example shows you how to instantiate a new object  
through script and
add it to another view.</p>

<example title="Script instantiation">
&lt;canvas height="120"&gt;
   &lt;class name="mybox"&gt;
     &lt;view bgcolor="${parent.bgcolor}" width="50" height="50"/&gt;
   &lt;/class&gt;

   &lt;view name="redbox" bgcolor="red" width="100" height="100"/&gt;

   &lt;!-- Create new mybox with cyan bgcolor and place it in  
canvas.redbox. --&gt;
   &lt;button x="110" text="add cyan"
             onclick="if (canvas.redbox['cyan'] == null)
                        new mybox(canvas.redbox, { name: 'cyan',  
bgcolor: 0x00ffff })"/&gt;

   &lt;!-- Remove cyan view from redbox. --&gt;
   &lt;button x="110" y="30" text="remove cyan"
             onclick="if (canvas.redbox['cyan'] != null)  
canvas.redbox.cyan.destroy()"/&gt;

&lt;/canvas&gt;
</example>
<h2>Class Names and Tag Names</h2>
<p>All classes are defined in the global namespace. If you wanted to  
instantiate
a class dynamically, you can write <code>new
global[classString](...)</code>. Using the previous example, mybox  
can be
instantiated like <code>new global['mybox'](canvas.redbox, { bgcolor:  
0x00ffff
})</code>.</p>
<h3>Mapping Class and Tag Names</h3>

<p>Be aware that names for tag classes are not the same as their
JavaScript counterpart; rather, the JavaScript name is <code>lz. 
[tagname]</code>. For example, to access a <tagname>view</tagname> in  
script, you would use <code>lz.view</code>. Thus, to instantiate a  
view through script, you would write
<code>new lz.view(...)</code> (<b>not</b> <code>new view(...)</code>).
<note>
In earlier versions of OpenLaszlo, there was an idosyncratic mapping  
between class names and tag names, and classes in the LFC were  
handled differently than user devfined classes. For example, the  
tagname <tagname>view</view> mapped to JavaScript class LzView. With  
OpenLaszlo 4.0, the <code>lz.[tagname]</code> mapping is universal,  
and the old mappings are deprecated. </note>



Begin forwarded message:

> So the refguide should just refer to all classes as `lz.<tagname>`  
> (and deprecate the `Lz*` names).



More information about the Laszlo-dev mailing list