PDA

View Full Version : Strange Behavior when adding/removing views


sandman
02-26-2003, 04:02 PM
Within a view I am displaying the following:
<text>
<a bold line> (a view with black background)
<text>
..

When an event occurs I remove all the subviews. Then on another user event I re-add the subviews. The text works fine but the height of the bold line increases to some random value. I essentially see a big black box. I am using the following method to delete subviews:
<method name="reset">
var sviews = this.subviews;
<![CDATA[
var i = sviews.length;
while (i > 0)
{
sviews[i-1].deleteNode();
--i;
}
]]>
</method>

I am using the following method to add sub views:

<method name="doSetUp">
this.tmpcharmSizeLabel = new charmSizeLabel(this);
this.tmpcharmSizeLabel.setAttribute ('sizeDescription', this.getAttribute('sizeDescription'));
this.tmpcharmSizeLabel.setAttribute('sizeId', this.getAttribute('sizeId'));
this.tmpcharmSizeLabel.setAttribute('width', 200);
this.tmpcharmSizeLabel.setAttribute('height', 100);
var charmSizeLabel_x = 30;
var charmSizeLabel_y = 10;
this.tmpcharmSizeLabel.setAttribute('x', charmSizeLabel_x);
this.tmpcharmSizeLabel.setAttribute('y', charmSizeLabel_y);
this.tmpcharmSizeLabel.doSetUp();

this.tmpview = new LzView(this);
this.tmpview.setAttribute('x', 15);
this.tmpview.setAttribute('y', 50);
this.tmpview.setAttribute('height', 2);
this.tmpview.setAttribute('width', 572);
this.tmpview.setAttribute('bgcolor', 'black');
</method>

When I call reset() and doSetUp() repeatedly I see the strange behavior.

hqm
02-26-2003, 04:08 PM
I think this might be a bug in the release having to do with how bringToFront() works, which was just fixed in the
development world. I will try to reproduce your bug in the dev world.

hqm
02-26-2003, 05:55 PM
Can you post or send me a complete working test case for your
bug? You can email it to hminsky@laszlosystems.com if you like.

hqm
02-27-2003, 12:51 PM
At runtime, you must use integers only for bgcolor values (not strings), and you also cannot use color names (like 'red'). Color names are only parsed in
the XML compilation phase, not by the runtime. The syntax "#ff0000" also is supported in XML but not by
Javascript.




<class name="navigationtab" extends="view">
<method event="onclick">
var myId = this.getAttribute('id');
this.setAttribute('bgcolor',0xAADB76);
this.setAttribute('clickable',false);
if (myId == 'profileTab')
{
storesTab.setAttribute('bgcolor',0xEBF7DD);
storesTab.setAttribute('clickable',true);
configuratorTab.setAttribute('bgcolor',0xEBF7DD);
configuratorTab.setAttribute('clickable',true);
}
else if (myId == 'storesTab')
{
profileTab.setAttribute('bgcolor',0xEBF7DD);
profileTab.setAttribute('clickable',true);
configuratorTab.setAttribute('bgcolor',0xEBF7DD);
configuratorTab.setAttribute('clickable',true);
}
else if (myId == 'configuratorTab')
{
profileTab.setAttribute('bgcolor',0xEBF7DD);
profileTab.setAttribute('clickable',true);
storesTab.setAttribute('bgcolor',0xEBF7DD);
storesTab.setAttribute('clickable',true);
}
</method>
</class>

hqm
02-27-2003, 12:52 PM
Cool widget, by the way!

adam
02-27-2003, 04:55 PM
deleteNode is somewhat unstable in the DR release.
There are two known bugs, and probably more unknown ones.

The known ones are that calling deleteNode on a pointer to a node you've already deleted hangs the player.

Second, when a node is deleted, it is not removed from the subviews array -- instead 'null' is written into the array in the place where the node used to be.

Still, neither of these issues would cause the problem you're seeing.

In general, it's best to avoid deleting nodes -- often the data replication feature along with a local dataset can replace this kind of functionality and works much better anyway.

sandman
02-28-2003, 09:56 AM
I am reading data from the database and then creating subviews. So, the data to be displayed changes based on user input. In this scenario the approach I was taking was to create subviews each time data is read and deleting the previously created subviews. Since deleteNode() has problems what would be the best approach? One way would be to reuse existing subviews and hiding those that are not needed. What do you suugest?

adam
02-28-2003, 10:25 AM
Hi Sandman.

You can definitely use deleteNode here. I ran your example and found two problems that were probably causing you the grief.

The first is that your canvas declaration is this:
<canvas width="1250" height="10050" title="Bracelet Configurator" debug="false">

This appears to cause problems for the flash player (when you change the height to 1050, the problem with refreshing the screen when you drag the debugger goes away.) I would recommend that you make your canvas size smaller -- I don't think many people have screens taller than 2000px.

The second problem is that you've declared your CharmsTypesView as a class that extends scrollbar. By doing this, your saying "CharmsTypesView isa scrollbar."

This causes problems, becuase the internals of the scollbar class have layouts and such that are intended only for displaying a scrollbar.

I think what you mean is "CharmsTypesView hasa scrollbar."

This is particularly easy to express in lzx.

Just change this:
<class name="CharmTypesView" extends="scrollbar">
to this:
<class name="CharmTypesView">
<scrollbar/>

sandman
02-28-2003, 12:34 PM
Thanks Adam. I didn't realize that I had put in such a big number for the height. You are right I really don't need a isA relationship with scrollbar, hasA is more appropriate.