PDA

View Full Version : to recognise the dynamically generated tabs


divaa
09-13-2007, 02:51 AM
hi

we are trying to create a chat front end, somethign similar to what we find in igoogle's gtalk.
we have successfully built the front end where we can display all the buddies present. on clickin the buddy a new tab is generated and is in the enabled mode.

this tab has 2 edittext fields, edit1, edit2

on typing message in edit2, it gets reflected in edit1 and also is sent to the buddy, backend code takes care about sending the message to the respective buddy.

the problem we have is .. when the buddy sends back a message, we get the buddy name + message from the buddy, but we do no tknow how to recognise the appropriate tab to display the message in.

please could u provide ur insight on this problem

senshi
09-13-2007, 01:28 PM
A simple proposal:


<class name="buddytabs" extends="tabs" >
<attribute name="mybuddies" value="$once{new Object()}" />

<method name="addBuddy" args="buddytp" >
this.mybuddies[buddytp.buddyname] = buddytp;
</method>

<method name="removeBuddy" args="buddytp" >
delete this.mybuddies[buddytp.buddyname];
</method>

<method name="handleNewMessage" args="buddyname, msg" ><![CDATA[
var buddy = mybuddies[buddyname];
if (buddy) {
buddy.handleNewMessage(msg);
}
]]></method>

<!-- your class stuff -->
</class>

<class name="buddytabpane" extends="tabpane" >
<attribute name="buddyname" value="" type="string" />

<method name="init" >
super.init.apply(this, arguments);
this.parent.addBuddy(this);
</method>

<method name="destroy" >
this.parent.removeBuddy(this);
super.destroy.apply(this, arguments);
</method>

<method name="handleNewMessage" args="msg" >
//do stuff here
</method>

<!-- your class stuff -->
</class>