_server.sendResponse with multi level object

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

u007
Posts: 18
Joined: 04 Sep 2009, 11:22

_server.sendResponse with multi level object

Postby u007 » 04 Sep 2009, 11:30

sendResponse works great if ive only 1 level of array or a hash / dictionary result.

but when i've more than 1 level, action script side is not able to pick it up correctly.
using flex and smartfox 1.6.6

example:
--------------
AS script on server:
--------------
var allwinners = [];
var oWinnerInfo;
//we got a winner!
oWinner = _server.getUserById(iUserId);
oWinnerInfo = {};
oWinnerInfo.id = iUserId;
oWinnerInfo.name = oWinner.getName();
oWinnerInfo.board = aWinner[d];

allwinners.push(oWinnerInfo);

var res = {};
res._cmd = "BingoWinner";
res.winners = allwinners;
res.msg = sMsg;
_server.sendResponse(res, oRoom.getId(), null, oRoom.getAllUsers(), _server.PROTOCOL_JSON);


----------
client side (as3/flex):
var data:Object = evt.params.dataObj;
trace(data.winners[0]) // return Object
trace(data.winners[0].name) // return undefined
trace(data.winners[0]["name"]) //return undefined as well

----------------

is there anyway to get it? please note that its on json protocol...
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 06 Sep 2009, 09:24

No errors on the server side when you send that data?
Can you show the json debug data getting to the client?
Lapo
--
gotoAndPlay()
...addicted to flash games
u007
Posts: 18
Joined: 04 Sep 2009, 11:22

debug?

Postby u007 » 07 Sep 2009, 02:46

where do i get the debug message?
there isnt any error on server ...
i ran the server with sh start.sh
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 07 Sep 2009, 06:27

Debug data is found in the output window of the Flash IDE (press F2)
You should also make sure that the debug flag of the SmartFoxClient instance is set to true.
Lapo

--

gotoAndPlay()

...addicted to flash games
u007
Posts: 18
Joined: 04 Sep 2009, 11:22

flex..

Postby u007 » 07 Sep 2009, 06:55

hi,
i'm using flex sdk without flash ide :(
any suggestion?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 07 Sep 2009, 06:57

No problem, simply run your code with the debugger and you'll see the debug data in the Flex console panel :)
Lapo

--

gotoAndPlay()

...addicted to flash games
u007
Posts: 18
Joined: 04 Sep 2009, 11:22

loader + flex

Postby u007 » 07 Sep 2009, 07:20

Hi,

I can't run flashplayer debugger version to call on the swf directly because i'm using Loader call to get the images photo.
i will face sandbox issue with it...

Is it possible for you to duplicate the code i've mentioned above to test?

thank you :)
u007
Posts: 18
Joined: 04 Sep 2009, 11:22

trying

Postby u007 » 07 Sep 2009, 07:25

Hi,

i just learned to use fdb, i'm checking on it now..
will update here...
u007
Posts: 18
Joined: 04 Sep 2009, 11:22

finally

Postby u007 » 07 Sep 2009, 08:35

ok, i've compiled it with debug=true...
installed flashplayer for linux based on debug more..

ran fdb
run ...

i'm seing debug messages coming through fdb, with [trace]
did some continue command several times..

and finally on finishing the game, there wasnt any error...
------------------------
[trace] XT Result: bingopicknumber
[trace] [ RECEIVED ]: {"t":"xt","b":{"r":7,"o":{"winners":[{"id":7,"board":[1,2,3,4,5]}],"_cmd":"BingoWinner","msg":"Someone Won! :"}}}, (len: 113)
[trace] XT Result: BingoWinner
------------------------

is there anything wrong with it?
u007
Posts: 18
Joined: 04 Sep 2009, 11:22

new findings

Postby u007 » 07 Sep 2009, 09:01

i changed my server code to:
oWinner = _server.getUserById(iUserId);
oWinnerInfo = {};
oWinnerInfo.id = iUserId;
oWinnerInfo.id2 = iUserId;
oWinnerInfo.username = "xx" + oWinner.getName();
oWinnerInfo.username2 = oWinner.getName();
oWinnerInfo.board = aWinner[d];

allwinners.push(oWinnerInfo);


results:
[trace] [ RECEIVED ]: {"t":"xt","b":{"r":7,"o":{"winners":[{"id":0,"username":"xxtest","id2":0,"board":[1,2,3,4,5]}],"_cmd":"BingoWinner","msg":"Someone Won! :"}}}, (len: 141)


notice the username2 is missing :(
why?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 08 Sep 2009, 08:42

Hi there,
I am not able to reproduce the problem.

I have just substituted the data:

Code: Select all

function getName()
{
   return "LAPO"
}

var allwinners = []
oWinner = { "getName" : getName } //_server.getUserById(iUserId);
oWinnerInfo = {};
oWinnerInfo.id = 1 //iUserId;
oWinnerInfo.id2 = 2 // iUserId;
oWinnerInfo.username = "xx" + oWinner.getName();
oWinnerInfo.username2 = oWinner.getName();
oWinnerInfo.board = [1,2,3,4,5]

allwinners.push(oWinnerInfo);

var res = {};
res._cmd = "BingoWinner";
res.winners = allwinners;
res.msg = "This is a simple message";

_server.sendResponse(res, -1, null, [user], "json")


On the client (AS3) I get:

Code: Select all

{"t":"xt","b":{"o":{"winners":[{"username2":"LAPO","id2":2,"username":"xxLAPO","board":[1,2,3,4,5],"id":1}],"_cmd":"BingoWinner","msg":"This is a simple message"},"r":-1}}


which looks right to me
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 08 Sep 2009, 08:45

Maybe you should verify that the JSON conversion is not wrong from server side (although I wouldn't see why)

Try this code before your sendResponse call:

Code: Select all

testJSON = __convertToJSON2(resObj)   
trace(testJSON)

where resObj is your response object, the same you are passing to sendResponse.

This will output in the console the JSON data
Lapo

--

gotoAndPlay()

...addicted to flash games
u007
Posts: 18
Joined: 04 Sep 2009, 11:22

solution

Postby u007 » 09 Sep 2009, 02:10

this seems to work:
oWinnerInfo.username = "" + oWinner.getName();

but thank you :)

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 32 guests