PDA

View Full Version : create a view with js


pep
05-19-2004, 07:44 PM
I want to add views dynamically with a js script, so I tried :


<view name="bar">
<simplelayout axis="x"/>
<method name="addSubV">
var foo=new LzView();
foo.construct(this,null);
foo.setAttribute('height',10);
foo.setAttribute('width',10);
foo.setAttribute('bgcolor',0x000000);
this.addSubview(foo);
</method>
</view>


but unfortunately the view is not created as a child of the current view (bar), but is directly attached to the root canvas.

did I missed something?

antun
05-20-2004, 09:01 AM
I'm not sure that's what addSubview is used for, although the note in the LZX Reference about it is rather sparse. I've filed a bug on it.

However the first argument to view's constructor is the parent node you want to add it to:


var foo=new LzView( this );


... would create a new view in the current view.

-Antun

mhelenek
10-15-2005, 09:07 PM
<?xml version="1.0" encoding="UTF-8" ?>
<canvas bgcolor="0x000000">

<view name="bar" bgcolor="0xFF0000" x="10" y="10" height="50" width="50">
<simplelayout axis="x"/>
<method name="addSubV" event="oninit">
var foo=new LzView(this);
foo.construct(this,null);
foo.setAttribute('height',30);
foo.setAttribute('width',30);
foo.setAttribute('x', 10);
foo.setAttribute('y', 10);
foo.setAttribute('bgcolor',0xFFFFFF);
this.addSubview(foo);
</method>
</view>
</canvas>

The output of this example will demonstrate that the view is attached to the view and not the canvas. Try changing or commenting out the x / y of foo to see teh difference.