-
[RESOLVED] add an icon in a list component
Hi,
Code:
smartfox.onJoinRoom = function(roomObj:Room) {
var userList:Object = roomObj.getUserList();
chat_txt.htmlText = "";
userList_lb.removeAll();
for (var i in userList) {
var user:User = userList[i];
userList_lb.addItem({icon:"sDona", data:user.getName(), label:user.getId()});
}
userList_lb.iconField = "icon";
userList_lb.sortItemsBy("label", "ASC");
};
this is the code where I'm trying to use an icon in the iconfield in my userlist but I'm getting a number back for the user.getId(), not the user's name. The icon is there.
How should I approach this? I'd like to add different icons depending on the user's gender.
-
.
Hi Cap,
try using userList_lb.addItem({icon:"sDona", data:user.getId(), label:user.getName()});
-
Thanks, is it possible to place it on the right side of the user?
I've changed the order to : userList_lb.addItem(data:user.getId(), label:user.getName(), {icon:"sDona"}); and I haven't been able but I bet that wouldn't be the way if possible...
-
.
Hi cap,
default positon is left, but you can work around it like so,
PHP Code:
for (var i in userList)
{
var user:User = userList[i];
var userIcon = userList_lb.attachMovie("sDona","sDona",1000,{_x:userList_lb._width - 50,_y:4});
userList_lb.addItem({icon:userIcon, data:user.getName(), label:user.getId()});
}
You will need to mess around with the numbers and of course you might need to do some sort of if else statement for the uVars of gender to get which icon to use.
something like
PHP Code:
var whichGender:String;
for (var i in userList)
{
var user:User = userList[i];
if(uVars.gender == "female")
{
whichGender = "sDona";
else
{
whichGender = "hom";
}
var userIcon = userList_lb.attachMovie(whichGender,whichGender,1000,{_x:userList_lb._width - 50,_y:4});
userList_lb.addItem({icon:userIcon, data:user.getName(), label:user.getId()});
}
Happy hunting and happy new year.
-
Happy new year !
Hi, I told myself to forget about ttrying to place the icon on the right side, since I need to understand other basic things before that so I have been trying with this code all afternoon.
Does it make any sense? If it does, it won't work. whenever the second user logs in, he still gets the first user's icon.
Code:
smartfox.onJoinRoom = function(roomObj:Room) {
var userList:Object = roomObj.getUserList();
chat_txt.htmlText = "";
userList_lb.removeAll();
for (var i in userList) {
var user:User = userList[i];
var uName = user.getName();
var uId = user.getId();
if (gender == "home") {
userList_lb.addItem({icon:"sHome", data:uId, label:uName});
} else if (gender == "dona") {
userList_lb.addItem({icon:"sDona", data:uId, label:uName});
}
}
if (uName != _global.myName) {
userList_lb.removeAll();
var uVars:Object = user.getVariables();
var whichGender:String;
for (var i in userList) {
var user:User = userList[i];
if (uVars.gender == "home") {
whichGender = "sHome";
} else if (uVars.gender == "dona") {
whichGender = "sDona";
}
userList_lb.addItem({icon:whichGender, data:uId, label:uName});
}
}
userList_lb.iconField = "icon";
userList_lb.sortItemsBy("label", "ASC");
chat_txt.htmlText += "<font color='#cc0000'>>> Room [ "+roomObj.getName()+" ] joined</font>";
setupMyUser();
};
function setupMyUser() {
smartfox.setUserVariables({gender:gender});
}
smartfox.onUserEnterRoom = function(fromRoom:Number, user:User) {
if(gender == "home"){
userList_lb.addItem({icon:"sHome", data:user.getId(), label:user.getName()});
} else if(gender == "dona"){
userList_lb.addItem({icon:"sDona", data:user.getId(), label:user.getName()});
}
userList_lb.iconField = "icon";
userList_lb.sortItemsBy("label", "ASC");
updateRoomStatus(fromRoom);
};
-
.
Hi Cap,
You will need to send the gender var to the server at this point setupMyAvatar then smartfox.setUserVariables so the list can use the correct icon for each user
Last edited by fruitbeard; 01-01-2015 at 02:03 PM.
-
Hi, thanks,
I'm doing that unless you mean different.
I'm setting them in the setupMyUser because I can't do it in joinRoom, which seemed like the most reasonable thing to do to me once the user joins the room.
-
.
Hi Cap,
Your code is a little confused, try something more like
PHP Code:
smartfox.onJoinRoom = function(roomObj:Room) { var userList:Object = roomObj.getUserList(); chat_txt.htmlText += "<font color='#cc0000'>>> Room [ " + roomObj.getName() + " ] joined</font>"; userList_lb.removeAll(); for (var i in userList) { var user:User = userList[i]; var uName = user.getName(); var uId = user.getId(); if (uName != _global.myName) { var uVars:Object = user.getVariables();
userList_lb.addItem({data:user.getId(), label:user.getName(), icon:uVars.gender}); } else { userList_lb.addItem({data:user.getId(), label:user.getName(), icon:gender}); } userList_lb.iconField = "icon"; } userList_lb.sortItemsBy("label", "ASC"); setupMyUser(); };
-
good morning, Fruit,
thanks, sure looks better that way, but I'm still having trouble.
I don't understand the way things happen for sure, because only the second user gets updated.
I've looked up at the avatar chat example and I noticed onUserEnterRoom gets variable updates as well. I've tried to set it the same way it is coded in there, but flash tells me I can't access a private member.
I am going to try and write it as above building an object to get the variables, but I fear it's not going to work. i think I've tried it several times already. Any ideas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|