View Full Version : Creating / removing subviews
scorpio
05-31-2004, 09:16 AM
Hi,
I was wondering what would be the result of this code:
a = new LzView()
b = new LzView()
c = new LzView()
a.addSubview(c);
b.addSubview(c);
will the c be a child of both a and b or just b?
addSubview can be overridden, but it can't be called. I've filed a bug on this.
A view's parent is fixed at construct time. To make view A the parent of view B, you'd write
new LzView( A , { name: 'B' } );
ctemplin
01-06-2005, 08:00 AM
It appears that in the new version 3 beta it is still not possible to add a child view at runtime. Is there any plan to fix this?
coszmin
02-18-2005, 12:16 AM
I badly needed this feature , as I wanted to reuse an instance over and over again for many things . Constructing a new object wasn't an option
so i noticed that addSubview doesn't work , then found this thread . I played with some ideeas , and managed to get the functionality done by using setAttribute on parent
Here's my test , for a clearer understanding :
<canvas height="700" width="700" debug="true">
<view id="fk">
<simplelayout axis="y" spacing="5"/>
<view id="vi" height="200" width="200" bgcolor="red"></view>
<view id="vii" height="150" width="150" bgcolor="yellow">
<method event="onparent">
debug.write("parent has been changed to " + this.parent);
this.setAttribute("x" , 0 );
this.setAttribute("y" , 0 );
</method>
</view>
<button>Baga
<method event="onclick">
// the winner
vii.setAttribute("parent" , vi);
// the winner
debug.write("vii parent e : " + vii.parent.id );
</method>
</button>
</view>
</canvas>
Hi coszmin,
Your code works perfectly. Great (and simple) idea.
Thank's a lot.
bfagan
08-15-2005, 06:12 AM
Of course, your item is not actually a subview. People reading this thread should not get confused. You simply positioned one view over another and set the parent reference.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.