Skip to main content
Known Participant
Nov 25, 2009 2:53 AM UTC
Question

Something wrong with my sync function. Help please.

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 is closed to new replies. Start a new post to keep the conversation going.

    9 replies

    Nov 26, 2009 5:22 AM UTC

    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

    Translate
    Known Participant
    Nov 26, 2009 6:06 AM UTC

    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.

    Translate
    calmchessplayer
    Inspiring
    Nov 25, 2009 3:59 AM UTC

    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

    Translate
    Known Participant
    Nov 26, 2009 2:58 AM UTC

    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.

    Translate
    calmchessplayer
    Inspiring
    Nov 26, 2009 4:02 AM UTC

    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"

    Translate