PDA

View Full Version : Solution needed


Anusha
03-25-2004, 02:23 AM
Dear All

I have a requirement in which on double click event of a button, say Button1, a floating list will appear and in that floating list I will be having a text box and a OK Button. After providing some text value in the text box and on press of the OK button the text box value is set to the Button1.

Now on single click of Button1, I need to populate another button say ChildButton. Similar to that of Button1, I will populate the floating list and provide value to the ChildButton.

I am attaching the code snippet which I have coded for this purpose.

The problem now is that the, value entered in the second button textbox get's into the first button value.But it should not happen in that way,only the value entered in the firstbutton text box should get entered into it's button value.For me it's happening in the reverse way...any solutions plz.

code :
---------
<canvas height="700" debug="true">
<class name="SpecialButton" extends="button" onclick="changeLabel()">
<method name="changeLabel">
debug.write(textbox.getText());
b1.setAttribute('text', textbox.getText() );
</method>
</class>
<class name="sbutton" extends="button" >
<attribute name="nextX" value="0"/>
<attribute name="nextY" value="0"/>
<fflist name="flist" />
<method event="onclick">
var foo = new cbutton( canvas, {text:'popupbutton' ,name:'popupbutton', y:60} );
</method>
<method event="ondblclick">
flist.setVisible(!flist.visible);
</method>
</class>
<class name="cbutton" extends="button" >
<attribute name="nextX" value="0"/>
<attribute name="nextY" value="0"/>
<fflist name="flist" />
<method event="ondblclick">
flist.setVisible(!flist.visible);
</method>
</class>
<class name="fflist" extends="floatinglist" attach="right" width="68" visible="false">
<edittext id="textbox" ></edittext>
<SpecialButton> OK </SpecialButton>
</class>
<sbutton text="Anusha" name="b1" x="20" y="10" />
</canvas>


---Anush

antun
03-25-2004, 09:21 AM
The problem now is that the, value entered in the second button textbox get's into the first button value.

I think that might be because you have given a view inside of a class definition an id:


<class name="fflist"
extends="floatinglist"
attach="right"
width="68"
visible="false">
<edittext id="textbox"></edittext>
<SpecialButton>OK</SpecialButton>
</class>


You must never use an id in a class definition, unless you are sure that class is going to be instantiated only once in your app. An id is global. In your case, you're using the fflist class in two places.

Also note that the onclick event gets sent even if the ondblclick event gets sent, so your sbutton class will make a new instance of cbutton every time. In general, it's good practice not to tie something to a single-click event that could harm the app, if you're using a double click event on the same element.

While you can dynamically instantiate views using the constructor (new...), it's not recommended. Consider using a <state> or having your cbutton instance invisible at the start, and just turning its visibility on. That would avoid the above problem of creating multiple instances of cbutton.

-Antun

-Antun

Anusha
03-28-2004, 09:27 PM
Hi Antun

I tried using the method as you said by making the components invisible and visible but the method you suggested would work only for already known components but for me, on click of a button the components should get generated dynamicaly in that fly and those components should possess the properties as it's parent button...any code snippet for the above mentioned requirement plz...

Regards
Anush