[Moved to laszlo-user]
Hello Chen,
if you add the menuitem to the menu's floatinglist, it'll work:
var item1 = new lz.mymenuitem(*mm.flist*, {text:"Item 1"}, []);
Cheers,
André
Hi There,
In my application, I like to be able to create menus dynamically through the 'new' operator. As can be seen from the following code, the same constructs, if created using tags, everything works perfectly. But for the same thing, using 'new' will mess up.
In general, I have the feeling that using tags is more reliable than using 'new'. I understand the advantages of being declarative. But occasionally, we may be forced to resort the 'new' way instead of the 'tag' way. My understanding is that the tag-way is just a convenience. Eventually (deep inside the implementation), it will eventually use the 'new'-way to create objects. Not sure whether this understanding is correct.
Thanks!
Chen Ding
<canvas debug="true">
<debug y="400"/>
<class name="mymenuitem" extends="menuitem">
<handler name="onselect">
Debug.write("menu item selected: ", this.text);
</handler>
</class>
<class name="mymenubar" extends="menubar"/>
<class name="mymenu" extends="menu"/>
<!-- Creating the menu declaratively. This works just fine -->
<mymenubar name="themenubar" width="200" >
<mymenu text="Menu 1" width="100">
<mymenuitem text="Item 1"/>
<mymenuitem text="Item 2"/>
</mymenu>
</mymenubar>
<!-- Trying to create the same menu using 'new' operator. It does not work!
-->
<button text="Create menubar" x="100" y="100">
<handler name="onclick">
var bb = new lz.mymenubar(canvas, {x : 300, width : 200}, []);
var mm = new lz.mymenu(bb, {text : "Menu 1", width : 100}, []);
var item1 = new lz.mymenuitem(mm, {text:"Item 1"}, []);
var item2 = new lz.mymenuitem(mm, {text:"Item 2"}, []);
</handler>
</button>
</canvas>
Below are the error messages I got when pressing the button:
WARNING: reference to undefined property 'classroot'
WARNING @lz/listitem.lzx#62: reference to undefined property 'classroot'
ERROR: Invalid event sender: immediateparent.classroot => ?undefined? (for event ontrackgroup)
ERROR: Invalid event sender: immediateparent.classroot => ?undefined? (for event ontrackgroup)