I am working on a dynamic avatar screen that is hooked to a database. You change the avatarIndex and then update the database. When you go into a game room, your avatar will reflect your change. (For game design reasons, I cannot do this within the game room.)
This works great in the avatar screen. You can make multiple changes, and they all get updated in the database. However, if you go into a game room, leave it, and then back to the avatar selection screen, the onExtensionResponse no longer receives the response from my extension.
I have traces in my extension that clearly show the updates are taking effect. I can even veryify the changes through MySQL Workbench. However, the extension response NEVER gets called.
My best guess is that I am not handling something properly when I leave the game room and go back to my lobby (often the chat room, in the examples), but I can't figure out what that would be.
Here's my code:
Click event in the avatar screen:
Code: Select all
function onUpdateData( evt:MouseEvent ):void
{
updateRecord();
}
function updateRecord()
{
// prepare the request object
var req:Object = {};
req.user_id = 1; // Just set it manually, for now
req.avatar_name = txtAvatarName.text;
req.avatar_index = (int(mc_standingAvatar.currentFrame)-1);
smartFox.sendXtMessage("myDatabaseExtension", "updateData", req, "xml");
}The request handler in myDatabaseExtension.as:
Code: Select all
function handleRequest(cmd, params, user, fromRoom)
{
trace(">>> handleRequest");
if (cmd == "updateData")
{
trace(">>> updateData");
var sql = "UPDATE user_table SET "
sql += " avatar_name='" + _server.escapeQuotes(params.avatar_name) + "',"
sql += " avatar_index='" + _server.escapeQuotes(params.avatar_index) + "' "
sql += " WHERE user_id='" + _server.escapeQuotes(params.user_id) + "'"
var success = dbase.executeCommand(sql)
if (success)
{
trace(">>> successful update");
var response = {}
response._cmd = "updateData"
response.user_id = params.user_id
response.user_name = params.user_name
response.avatar_name = params.avatar_name
response.avatar_index = params.avatar_index
trace(">>> sending server response");
_server.sendResponse(response, -1, null, [user])
}
}
}My onExtensionResponse handler:
Code: Select all
function onExtensionResponse( evt:SFSEvent ):void
{
trace("onExtensionResponse");
var resObj:Object = evt.params.dataObj
var type:String = evt.params.type
var db_entry:Object = new Object();
messageQueue.push({ resObj: resObj, type: type })
trace("cmd: " + resObj._cmd)
trace("type: " + type)
// We expect the response to be xml formatted
if (type == "xml")
{
// Let's check if it's a "getData" message
if (resObj._cmd == "updateData")
{
delete resObj._cmd
trace("--- Update response is: ---");
trace("resObj.user_id = " + resObj.user_id);
trace("resObj.user_name = " + resObj.user_name);
trace("resObj.avatar_name = " + resObj.avatar_name);
trace("resObj.avatar_index = " + resObj.avatar_index);
smartFox.setUserVariables({ uAvatarName: resObj.avatar_name, uAvatarIndex: resObj.avatar_index});
Globals.vars.myAvatarIndex = resObj.avatar_index;
trace("Globals.vars.myAvatarIndex = " + Globals.vars.myAvatarIndex);
trace("-------------------------------");
}
}My leaveGameRoom handler: (I've tried different combinations of these three lines.)
Code: Select all
function leaveGameRoom():void
{
smartFox.joinRoom( "Lobby", "" );
gotoAndStop( "lobby" );
smartFox.getRoomList();
}My roomListUpdate handler:
Code: Select all
function onRoomListUpdate( evt:SFSEvent ):void
{
removeEventListener(Event.ENTER_FRAME, updateFilter);
if (LOGGING_IN) {
gotoAndStop( "check" );
} else {
gotoAndStop("lobby");
}
}If any of you know what's going on, I would be extremely grateful.
Thanks in advance.