please help a beginner with bits

Everything about the SmartFoxBits UI Components for SmartFoxServer 2X. Post your questions, suggestions and bug reports.

Moderators: Lapo, Bax

User avatar
gg
Posts: 82
Joined: 19 Sep 2010, 21:16
Contact:

please help a beginner with bits

Postby gg » 20 Feb 2013, 23:24

Hi, I am new to Bits. Could I get code examples on how to do the following? If you point me to the API, please give me a direct link to where the code example is as I am really bad with finding it myself.

1) If the room already has 2 players in it, and a 3rd player clicks on it, is there a way to disable, or not display the "Play" button at all? I'm using the AS3 Bits. So I'd like the user to only be able to Watch if the room is full with players.

2) In the chat, how can I display the message on the same line as the nickname ? The default behavior is to insert a new line after the nickname, and then the message.

3) In the lobby, can I add a button that when clicked, buzzes the player (plays a sound on that player's computer)?

Thank you!
Last edited by gg on 17 Mar 2013, 04:29, edited 2 times in total.
User avatar
Bax
Site Admin
Posts: 4332
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: play button and Chat question

Postby Bax » 21 Feb 2013, 08:17

1) Not possible. In order to do it you should get the source code and add a check on the Room selection event. I think it will be easy to do.

2) Check the messageHeader property: http://bits.smartfoxserver.com/docs/as3 ... sageHeader
The default header contains a <br> at the end, which makes the message itself go to the next line. Simply remove it and you will get what you need.

3) Yes sure. The lobby example is built using Bits, but you can add your own controls too. Of course you can't add it inside one of the Bits (for example you can't add that button inside the UserList component).
Paolo Bax
The SmartFoxServer Team
User avatar
gg
Posts: 82
Joined: 19 Sep 2010, 21:16
Contact:

Re: play button and Chat question

Postby gg » 15 Mar 2013, 20:11

Hi, I must be missing something

I'm trying to use the labelFunction so I can display the rating of the user. It needs to go to the database to retrieve it. Am I on the right path?

I'm following this example:
http://bits.smartfoxserver.com/docs/as3 ... elFunction

I added it into Flash Builder (I'm building on the Tris example in sfs2x ) - I added in the Tris.as file the following, as the example shows:

function setCustomUserLabel(item:Object):String
{
var user:User = item.userData
var label:String = "<font"

if (item.newMsgCount > 0)
label += " color='#" + newPrivateMsgLabelColor.toString(16) + "'"

label += ">" + user.getName() + "</font>"

if (item.newMsgCount > 0)
{
label += "<br>"
label += "<font size='10' color='#666666'>"
label += String(item.newMsgCount) + " message" + (item.newMsgCount > 1 ? "s" : "") + " to read"
label += "</font>"
}
return label
}

but a couple of functions are not recognized:
there is no newPrivateMsgLabelColor (ok I removed it) but:
getName is not a recognized function for the user variable (even after I imported com.smartfoxserver.v2.entities.User;)

What am I doing wrong?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: play button and Chat question

Postby rjgtav » 16 Mar 2013, 13:16

Hello,

Are you using SFS2X? If so, it seems you're consulting the wrong AS3 Client API Documentation, as for the SFS2X AS3 Client API the User object doesn't have a getName() method, but has a name property, which indicates the name of that user.
The correct Client API Documentation is located here:
http://docs2x.smartfoxserver.com/api-docs/asdoc/

Cheers
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
gg
Posts: 82
Joined: 19 Sep 2010, 21:16
Contact:

Re: play button and Chat question

Postby gg » 16 Mar 2013, 18:15

Thanks, I do use sfs2x. Why is the bits example using user.getName() ? Now I don't get an error but I don't get my modified message either.

I still don't think I'm using bits the right way. This is my onLogin function in the Tris.as file in Flash Builder (using the Tris example). I modified it to say "!!!!" instead of "to read", but I still get "to read" -

- do I need to capture the event where the user sends a message??
- am I even doing it in the right place? (in the onLogin function?)
- once I find out how to use the bits the right way, how do I display the user rating (from the database?)

private function onLogin(evt:SFSEvent):void
{
// Check if the "game" group is already subscribed;
// if not, subscribe it
if (!sfs.roomManager.containsGroup(GAME_ROOMS_GROUP_NAME))
sfs.send(new SubscribeRoomGroupRequest(GAME_ROOMS_GROUP_NAME));
// Move to chat view, and display user name
mainView.selectedChild = view_lobby;
lb_myUserName.text = sfs.mySelf.name;

var userList:UserList = new UserList();

// Set UserList instance properties (for example disable private chat)
userList.enablePrivateChat = false
userList.labelFunction=setCustomUserLabel;

function setCustomUserLabel(item:Object):String
{
var user:User = item.userData
var label:String = "<font"
if (item.newMsgCount > 0)
label += " color=red"
label += ">" + user.name + "</font>"
if (item.newMsgCount > 0)
{
label += "<br>"
label += "<font size='10' color='#666666'>"
label += String(item.newMsgCount) + " message" + (item.newMsgCount > 1 ? "s" : "") + " !!!!"
label += "</font>"
}
return label
}
// Add userList instance to stage
mainView.addChild(userList);
}

thank you so much for your help
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: play button and Chat question

Postby rjgtav » 16 Mar 2013, 18:31

What bits example are you referring to?
And the message you edited only appears when there is more than 0 private messages to read. For testing, are you using 2 clients where one sends a private message to the other?

Thanks
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
gg
Posts: 82
Joined: 19 Sep 2010, 21:16
Contact:

Re: play button and Chat question

Postby gg » 16 Mar 2013, 18:35

rjgtav wrote:What bits example are you referring to?
Thanks

http://bits.smartfoxserver.com/docs/as3 ... elFunction
Where does this code go, did I even put it in the right location (in Tris.as ?), onLogin method? Most likely not, since nothing is happening.

And the message you edited only appears when there is more than 0 private messages to read. For testing, are you using 2 clients where one sends a private message to the other?

yes
Last edited by gg on 17 Mar 2013, 04:21, edited 1 time in total.
User avatar
gg
Posts: 82
Joined: 19 Sep 2010, 21:16
Contact:

Re: play button and Chat question

Postby gg » 16 Mar 2013, 18:54

I'm clearly using the bits wrong, is there a tutorial on how to use them with a flash example that uses Flex?
User avatar
gg
Posts: 82
Joined: 19 Sep 2010, 21:16
Contact:

Re: please help a beginner with bits

Postby gg » 17 Mar 2013, 04:42

So the code example in the labelFunction property doesn't work as it is, it needs some tweaking... here's what I did:

- In Tris.mxml, I added labelFunction="setCustomUserLabel()" to sfb:UserList id="ul_players" ; result = s an error message says it's undefined. That's fine.
- in Tris.as, I added the setCustomUserLabel() function (exactly as it's explained here - http://bits.smartfoxserver.com/docs/as3 ... elFunction); result : the previous error (setCustomUserLabel is undefined)goes away from Tris.mxml, but I have 2 errors in Tris.as:
    1120: Access of undefined property newPrivateMsgLabelColor. (on the line with label += " color='#" + newPrivateMsgLabelColor.toString(16) + "'"
    1061: Call to a possibly undefined method getName through a reference with static type com.smartfoxserver.v2.entities:User. (on the getName() function

I changed getName() to name, and the second error went away. Hardcoded the color instead of using newPrivateMsgLabelColor, and now it finally works.

I also found out how to display the rating from the database by setting the user variable on the server side and getting it in that function. Thank you so much for the help!

Is there a way to display myself(the current user) in the list?
User avatar
Bax
Site Admin
Posts: 4332
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: please help a beginner with bits

Postby Bax » 17 Mar 2013, 11:07

No, displaying mySelf is not possible.
Paolo Bax
The SmartFoxServer Team
User avatar
gg
Posts: 82
Joined: 19 Sep 2010, 21:16
Contact:

Re: please help a beginner with bits

Postby gg » 19 Mar 2013, 21:15

My setCustomUserLabel() function works fine when I connect the first time, but after I play a game, it still displays the old rating. Is there a way to force a refresh on the user label ?

Return to “SmartFoxBits for SFS 2X”

Who is online

Users browsing this forum: No registered users and 1 guest