PDA

View Full Version : Adding/Removing subviews


sandman
02-18-2003, 01:22 PM
Hi,

Is it possible to add and remove subviews? I want to be able to add a subview when a particular event happens and then delete it on a different event.

thanks,
Sandeep.

adam
02-18-2003, 02:34 PM
Sure, it's easy!
just new a view like this:

<method..
this.tmpview = new LzView( this , { width: 20 , height:...


The first parameter to the constructor is the parent view (which is this, if the view that wants a new subview is running the code.) The second is a anonymous javascript object whose slots are the names of attributes for the new view and whose values are values for those attributes.

Note that can also new any subclass of view that you define

<class name="myclass" ...
...
<method
this.tmpview = new myclass( ... );


When you want to get rid of the view, call deleteNode

<method..
this.tmpview.deleteNode()


One note of caution... trying to delete the same view twice causes the Flash player to hang, so don't do it! (We'll have a fix in the next release, though.)

antun
02-18-2003, 02:44 PM
Hey Sandeep

Another way to do this is using states. States may or may not be more practical for your application:-


<canvas>
<simplelayout axis="y" spacing="5" />
<view id="myView"
bgcolor="0xe5e5e5" width="300" height="200" x="35" y="35">
<state name="extraView">
<view bgcolor="0xff0000" width="100" height="100" />
</state>
</view>

<button label="add" onclick="myView.extraView.apply();" />
<button label="remove" onclick="myView.extraView.remove();" />
</canvas>


Take care,

Antun