Adobe Connect User Community
Menu

#1 2012-03-20 09:22:01

**_elliotrevan_**

Sync Message Puzzle

Hi guys,

Can anyone explain to me why I can use associative arrays in sync messages if they are explicitly defined like this:

///////////////////////////////////////////

function that sends sync message:

///////////////////////////////////////////

connector.dispatchSyncMessage("add", {position:positionNS.value, question:questionTI.text, questionType:questionTypeCB.selectedLabel,
                    mandatory:mandatoryCB.selected, questionID:questionID, answers:answersString}, true);

///////////////////////////////////////////////

connector_syncMessageReceivedHandler

///////////////////////////////////////////////

var tempQuestion:Object = event.data.msgVal;
questions.addItem(tempQuestion)

__________________________________________________________________________________________________________
Now this works fine does exactly what I want it to, however if I dynamically create the sync message like this:
___________________________________________________________________________________________________________

///////////////////////////////////////////

function that sends sync message:

///////////////////////////////////////////


//now make result string for sync message
                var resultString:String = new String;
                resultString = "{userName:\""+connector.userName+"\", ";

// loop through survey results array to create associative array string for sync message
                for (i=0; i < survey.numChildren; i++)
                {
                    //get the each answer object and add question ID and value to results associative array string for sync message
                    child = survey.getChildAt(i) as Object;
                   
                    if (i >= 0 && i < survey.numChildren-1)
                    {
                        resultString +=        child.getQuestionID()+":\""+child.getStringValue()+"\",";   
                    }
                    if (i == survey.numChildren-1)
                    {
                        resultString += child.getQuestionID()+":\""+child.getStringValue()+"\"}";
                    }
           
                }

//and send sync message including the string that has been built to all other users
connector.dispatchSyncMessage("submit",resultString, true);   




///////////////////////////////////////////////

connector_syncMessageReceivedHandler

///////////////////////////////////////////////

var surveyObject:Object = event.data.msgVal;
                    results.addItem(surveyObject);

__________________________________________________________________________________________________________
For the first user who sends a message and has the result added to their local results array everything looks fine. Now for the second user user that receives the sync message and tries to display the results tab using the results data grid (where "results" is the data provider), the custom pod crashes.

Before it crashes when I go to the survey tab (as the second user), if I submit the answers and go back to the first user and look at the results tab, for each column in the datagrid I can see the full associative array as a string eg. {userName:user, question1:answer, question2:answer}. View the results tab for the second who has not added anything locally yet and it crashes.

___________________________________________________________________________________________________________



As far as I can tell the only difference is that the sync message string is dynamically created in the latter and explicitly defined in the former, however if the sync message can only be a string in the first place why would it make any difference? Does anyone have any explanations or methods for sending dynamically created associative arrays in a sync message. I am tempted to rewrite the whole application using XML but so far I have found no way of drilling into the data without using RPC utils, is there a better way to send dynamic associative array in a sync message, JSON libraries?

Last edited by **_elliotrevan_** (2012-03-20 09:27:49)

Offline

#2 2012-03-20 09:56:48

alistairlee

Re: Sync Message Puzzle

In theory, the dynamically created array's should work.  I don't have an answer as to why the dynamic approach isn't working, but I might have a solution.

The sync message value doesn't have to be a string.  You can create your own object class.  Something like a 'myQuestion' class with the attributes of position, questiontype, mandatory, etc

Offline

#3 2012-03-20 10:06:49

**_elliotrevan_**

Re: Sync Message Puzzle

AAhhhhhhhh! That would explain why it isn't working, I thought the messages have to be strings, if they can be raw data or something else that that would explain why an explicitly created object works but a dynamically created string turned into an object doesn't. Because it might not be turning back into an object/associative array correctly

I am going to try to send an object as the message and if that works then I don't have to do anything.
If that fails then I will try you what you suggested and if that fails I will turn all the messages into JSON.

Thank you alistairlee yet again. :)

Last edited by **_elliotrevan_** (2012-03-20 10:26:03)

Offline

#4 2012-03-20 10:10:12

alistairlee

Re: Sync Message Puzzle

I just wanted to add a bit of clarity to my last post.

For the Roshambo game I created, I wanted to pass a number of variables (name, choice, score) about each player.  Instead of dynamically creating an array, I created a new class called Playa.  Flash Builder automatically added a Playa.as file to my project and I added the following code:

package
{
    public class Playa
    {
        public var name:String;
        public var choice:String;
        public var score:int;
        
        public function Playa()
        {
        }
    }
}

In my main project file, I added two new variables based on this class:

var player1:Playa = new Playa();
var player2:Playa = new Playa();

Then, later on in my project in one of the functions, I dynamically populated player1 and player2:

player1.name = syncConnector.userName;
player1.choice = "scissors";

syncConnector.dispatchSyncMessage("p1Ready",player1,false);

During the syncMessageReceived handler, I reversed the process:

player1.name = evt.data.msgVal.name;
player1.choice = evt.data.msgVal.choice;

Hope this helps...

Offline

#5 2012-03-20 10:15:11

**_elliotrevan_**

Re: Sync Message Puzzle

*slaps forehead*

This changes everything for me, I can simply send objects to all users. I have no idea why I thought everything had to be strings.

Thank you alistairlee I have resolved my issue :)

Last edited by **_elliotrevan_** (2012-03-20 10:16:03)

Offline

#6 2012-03-20 10:18:32

alistairlee

Re: Sync Message Puzzle

Glad I could help.

BTW - if you develop something you'd like to give (or sell) to other customers, we might be able to feature it on the Adobe Connect Extensions page:
http://www.adobe.com/products/adobeconnect/extend.html

There's an email on the bottom of the page you can use to submit a custom pod.

Offline

#7 2012-03-20 10:46:50

**_elliotrevan_**

Re: Sync Message Puzzle

alistairlee wrote:

Glad I could help.

BTW - if you develop something you'd like to give (or sell) to other customers, we might be able to feature it on the Adobe Connect Extensions page:
http://www.adobe.com/products/adobeconnect/extend.html

There's an email on the bottom of the page you can use to submit a custom pod.

Hi Alistair,

That is a very kind offer and I will take you up on that when we are ready. We have a few products in the pipeline that may interest you. Unfortunately our website is still being developed, as soon as we have a public face so to speak, the first thing I will do is get in touch.

Offline

Board footer