| Package | com.smartfoxserver.v2.requests.game |
| Class | public class InviteUsersRequest |
| Inheritance | InviteUsersRequest com.smartfoxserver.v2.requests.BaseRequest |
Invitations can be used for different purposes, such as requesting users to join a game or visit a specific Room, asking the permission to add them as buddies, etc. Invited users receive the invitation as an invitation event dispatched to their clients: they can accept or refuse it by means of the InvitationReplyRequest request, which must be sent within the specified amount of time.
See also
| Method | Defined By | ||
|---|---|---|---|
InviteUsersRequest(invitedUsers:Array, secondsForAnswer:int, params:ISFSObject)
Creates a new InviteUsersRequest instance. | InviteUsersRequest | ||
| InviteUsersRequest | () | Constructor |
public function InviteUsersRequest(invitedUsers:Array, secondsForAnswer:int, params:ISFSObject)Creates a new InviteUsersRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
ParametersinvitedUsers:Array — A list of User objects representing the users to send the invitation to.
| |
secondsForAnswer:int — The number of seconds available to each invited user to reply to the invitation (recommended range: 15 to 40 seconds).
| |
params:ISFSObject — An instance of SFSObject containing custom parameters which specify the invitation details.
|
See also
private function someMethod():void
{
// Add a listener to the invitation reply
sfs.addEventListener(SFSEvent.INVITATION_REPLY, onInvitationReply);
// Choose the invitation recipients
var friend1:User = sfs.userManager.getUserByName("Piggy");
var friend2:User = sfs.userManager.getUserByName("Gonzo");
// Set the custom invitation details
var params:ISFSObject = new SFSObject();
params.putUtfString("msg", "Would you like to join me in my private room?");
params.putUtfString("roomName", "Kermit's room");
params.putUtfString("roomPwd", "drowssap");
// Send the invitation; recipients have 20 seconds to reply before the invitation expires
sfs.send(new InviteUsersRequest([friend1, friend2], 20, params));
}
private function onInvitationReply(evt:SFSEvent):void
{
// If at least one recipient accepted the invitation, make me join my private Room to meet him there
if (evt.params.reply == InvitationReply.ACCEPT)
{
var currentRoom:Room = sfs.lastJoinedRoom;
if (currentRoom.name != "Kermit's room")
sfs.send(new JoinRoomRequest("Kermit's room"));
}
else
{
trace(evt.params.invitee + " refused the invitation")
}
}