Skip to main content
Known Participant
November 25, 2009
Question

Something wrong with my sync function. Help please.

  • November 25, 2009
  • 2 replies
  • 903 views

Basically I want 3 users to connect up to the application to start the game. When the game starts...it displays a "Game has started" message on the clients' screens. I used shared object for this. However when i ctrl-enter the fla file...it says:

TypeError: Error #2007: Parameter text must be non-null.
    at flash.text::TextField/set text()
    at chemion_cs3_fla::MainTimeline/syncSO()

I dont know what it means. How to solve this problem? These are my codes:

=====================================================

Client side

=====================================================

var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onstatus1);
nc.connect("rtmp://localhost/myapplication2");

var txt1:SharedObject;
function onstatus1 (event:NetStatusEvent): void

{

            switch (event.info.code)
            {
               case "NetConnection.Connect.Success":
                    trace("Congratulations! you're connected");


                    nc.client = this;
                    txt1 = SharedObject.getRemote("GameStartText", nc.uri, false);
                    txt1.connect(nc);
                    txt1.addEventListener(SyncEvent.SYNC, syncSO);
                    break;

               case "NetConnection.Connect.Failed":

               ... ...

            }

}

function syncSO(event:SyncEvent):void{
    gameStart_txt.text = txt1.data.msg;
}


function StartGamee():void{
    txt1.setProperty("msg", "Game has started");

}

... ...

====================================================

Server side

====================================================

application.allowDebug = true;

application.onAppStart = function(){
    this.userID = 0;
}

application.onConnect = function(clientObj){
    application.acceptConnection(clientObj);
    clientObj._uniqueUserID = this.userID;
    this.userID++;
   
    if(this.userID == 3){
        clientObj.call("startGamee", null);
    }
}

application.onDisconnect = function(clientObj){

...
}

    This topic has been closed for replies.

    2 replies

    November 26, 2009

    It may be happening that startGamee() function is not being called from the server and so the msg property is not being set.

    just after making the connection and making nc.client = this  add following line

    nc.client.StartGamee = StartGamee;

    Also add a trace in StartGamee function to check whether control passes to that function.

    I hope it will solve your problem.

    Thanks,

    Abhishek

    Known Participant
    November 26, 2009

    Thanks for your reply. I tried to do as you said but this error message appeared.

    ReferenceError: Error #1037: Cannot assign to a method startGamee on chemion_cs3_fla.MainTimeline.
        at chemion_cs3_fla::MainTimeline/onstatus1()


    switch (event.info.code)
         {
         case "NetConnection.Connect.Success":                   

         trace("Congratulations! you're connected");
         nc.client = this;
         nc.client.startGamee = startGamee;
         txt1 = SharedObject.getRemote("GameStartText", nc.uri, false);
         txt1.connect(nc);
         txt1.addEventListener(SyncEvent.SYNC, syncSO);

         ... ... ...

    Also add a trace in StartGamee function to check whether control passes to that function.


    Yup, i think it works. I changed the user limit to 1, so the function gets called when one user enters the room. And the trace statement was traced.

    calmchessplayer
    Inspiring
    November 25, 2009

    are you using AS3? From the looks of your code you are therefore you have to create and intialize a text feild either with actionscript or by accessing the text field from within your document class.........is your onsync event within the document class ? If you have your code on the timeline then does your text field have an instance name of gameStart_txt ???

    Your complete problem is the text feild is not available

    Known Participant
    November 26, 2009

    Yea, I am using AS3. I put a dynamic text field on stage and gave it the instance name of gameStart_txt.

    I tried:


    function syncSO(event:SyncEvent):void
    {
        gameStart_txt.text = "testing"; 
    }

    and the text was able to be displayed on all of the clients' screens. But somehow when I changed it to txt1.data.msg; it didnt work.

    calmchessplayer
    Inspiring
    November 26, 2009

    so you have  this..........txt1.data.msg = "test";

    then you have      

    function syncSO(event:SyncEvent):void{

    gameStart_txt.text = txt1.data.msg;

                                                                          }

    //output in text box should be "test"