Adobe Connect User Community
Menu

#1 2010-02-24 15:11:25

**_Tgaudreau_**

How to sync drag and drop game (testSquare.fla) with multiple objects

I am trying to construct a drag and drop game using action script and the syncSWF SDK. The problem that i am having is that when i try to add more than one instance of the obj_mc, so that there is more than one object being manipulated on screen by multiple users, it only syncs to one instance. Can anyone spot the problem in my code?


var tracy_obj:Object=new Object();
tracy_obj._x=0;
tracy_obj._y=0;
tracy_obj.coordArray=new Array(tracy_obj._x,tracy_obj._y);   


tracy_obj.onPress=function(){
   
    this.startDrag()};
   
    tracy_obj.coordArray[0]=this._x;
    tracy_obj.coordArray[1]=this._y;
   
    this.syncThis("onPress",this.coordArray);


tracy_obj.onRelease=function(){
    // trace ("onRelease:");
    this.stopDrag();
    tracy_obj.coordArray[0]=this._x;
    tracy_obj.coordArray[1]=this._y;
    this.syncThis("onRelease",this.coordArray);
   
    }



tracy_obj.syncThis=function(message,theObj){
   
    trace ("firing syncConnector from "+ syncConnector.userID+" - syncThis: "+message+" " + theObj);
                                                                    
    syncConnector.dispatchSyncMessage(message,theObj);   
    }


syncConnector.addEventListener("caughtUp", this);

function caughtUp()
{
   
    trace ("fn: caughtUp > connection ready");   

   
}



function syncMessageReceived(p_evt){
    trace("syncMessageReceived - fired by "+syncConnector.userID);
    trace("p_evt.messageValue="+p_evt.messageValue);
    switch(p_evt.messageType){
            case "onRelease":
                trace ("onRelease");
               
                x_mc3._x=p_evt.messageValue[0];
                x_mc3._y=p_evt.messageValue[1];
               
            break;
           
            case "onPress":
                trace ("onPress");
                x_mc3._x=p_evt.messageValue[0];
                x_mc3._y=p_evt.messageValue[1];
               
            break;
       
        }

}

syncConnector.addEventListener("syncMessageReceived", this);

this.attachMovie("x_mc","x_mc3",this.getNextHighestDepth(),tracy_obj);
trace ("begin");




//=======================================================================
//=======================================================================




var tracy_obj2:Object=new Object();
tracy_obj2._x=0;
tracy_obj2._y=100;
tracy_obj2.coordArray=new Array(tracy_obj2._x,tracy_obj2._y);   


tracy_obj2.onPress=function(){
   
    this.startDrag()};
   
    tracy_obj2.coordArray[0]=this._x;
    tracy_obj2.coordArray[1]=this._y;
   
    this.syncThis("onPress",this.coordArray);


tracy_obj2.onRelease=function(){
   
    this.stopDrag();
    tracy_obj2.coordArray[0]=this._x;
    tracy_obj2.coordArray[1]=this._y;
    this.syncThis("onRelease",this.coordArray);
   
    }



tracy_obj2.syncThis=function(message,theObj){
   
    trace ("firing syncConnector from "+ syncConnector.userID+" - syncThis: "+message+" " + theObj);
                                                                
    syncConnector.dispatchSyncMessage(message,theObj);   
    }

syncConnector.addEventListener("caughtUp", this);

function caughtUp()
{
   
    trace ("fn: caughtUp > connection ready");   

   
}



function syncMessageReceived(p_evt){
    trace("syncMessageReceived - fired by "+syncConnector.userID);
    trace("p_evt.messageValue="+p_evt.messageValue);
    switch(p_evt.messageType){
            case "onRelease":
                trace ("onRelease");
               
                x_mc2._x=p_evt.messageValue[0];
                x_mc2._y=p_evt.messageValue[1];
               
            break;
           
            case "onPress":
                trace ("onPress");
                x_mc2._x=p_evt.messageValue[0];
                x_mc2._y=p_evt.messageValue[1];
               
            break;
       
        }

}

syncConnector.addEventListener("syncMessageReceived", this);

this.attachMovie("x_mc","x_mc2",this.getNextHighestDepth(),tracy_obj2);
trace ("begin");

Offline

#2 2010-02-26 09:36:32

**_palkan_**

Re: How to sync drag and drop game (testSquare.fla) with multiple objects

you've got 2  functions synchMessageReceived(), but only the one of them works, the second one is ignored.

You can not have two different functions with the same name in your code!

The simple way to realize your game is to differ the messages ("onRelease1", "onRelease2",etc.) or to expend your objects with some new properties, e.g. x_num:Number; and use these properties in synchMessageReceived() to define the MC to synchronize.

Offline

#3 2010-03-03 12:47:05

**_Tgaudreau_**

Re: How to sync drag and drop game (testSquare.fla) with multiple objects

Thanks for your response! Can you be a little more specific and show me where in the code to change the messages, or where to define new properties. i tried changing the messages in each of the sync funtions but that doesn't seem to work. I am a newbie at code and specifically to the syncSWF SDK. Any more detail you can provide would be GREATLY appreciated. If there are any good resources out there that may be useful as well that would be nice. Thanks!

Offline

#4 2010-03-05 07:56:52

**_palkan_**

Re: How to sync drag and drop game (testSquare.fla) with multiple objects

Here is the code for "different messages" method:


var tracy_obj:Object=new Object();
tracy_obj._x=0;
tracy_obj._y=0;
tracy_obj.coordArray=new Array(tracy_obj._x,tracy_obj._y);   


tracy_obj.onPress=function(){
   
    this.startDrag()};
   
    tracy_obj.coordArray[0]=this._x;
    tracy_obj.coordArray[1]=this._y;
   
    this.syncThis("onPress",this.coordArray);


tracy_obj.onRelease=function(){
    // trace ("onRelease:");
    this.stopDrag();
    tracy_obj.coordArray[0]=this._x;
    tracy_obj.coordArray[1]=this._y;
    this.syncThis("onRelease",this.coordArray);
   
    }



var tracy_obj2:Object=new Object();
tracy_obj2._x=0;
tracy_obj2._y=100;
tracy_obj2.coordArray=new Array(tracy_obj2._x,tracy_obj2._y);   


tracy_obj2.onPress=function(){
   
    this.startDrag()};
   
    tracy_obj2.coordArray[0]=this._x;
    tracy_obj2.coordArray[1]=this._y;
   
    this.syncThis("onPress1",this.coordArray);


tracy_obj2.onRelease=function(){
   
    this.stopDrag();
    tracy_obj2.coordArray[0]=this._x;
    tracy_obj2.coordArray[1]=this._y;
    this.syncThis("onRelease1",this.coordArray);
   
    }


tracy_obj.syncThis=function(message,theObj){
   
    trace ("firing syncConnector from "+ syncConnector.userID+" - syncThis: "+message+" " + theObj);
                                                                   
    syncConnector.dispatchSyncMessage(message,theObj);   
    }


tracy_obj2.syncThis=function(message,theObj){
   
    trace ("firing syncConnector from "+ syncConnector.userID+" - syncThis: "+message+" " + theObj);
                                                               
    syncConnector.dispatchSyncMessage(message,theObj);   
    }


syncConnector.addEventListener("syncMessageReceived", this);

this.attachMovie("x_mc","x_mc3",this.getNextHighestDepth(),tracy_obj);
trace ("begin");

this.attachMovie("x_mc","x_mc2",this.getNextHighestDepth(),tracy_obj2);
trace ("begin");



syncConnector.addEventListener("caughtUp", this);

function caughtUp()
{
   
    trace ("fn: caughtUp > connection ready");   

   
}



function syncMessageReceived(p_evt){
    trace("syncMessageReceived - fired by "+syncConnector.userID);
    trace("p_evt.messageValue="+p_evt.messageValue);
    switch(p_evt.messageType){
            case "onRelease":
                trace ("onRelease");
               
                x_mc3._x=p_evt.messageValue[0];
                x_mc3._y=p_evt.messageValue[1];
               
            break;
           
            case "onPress":
                trace ("onPress");
                x_mc3._x=p_evt.messageValue[0];
                x_mc3._y=p_evt.messageValue[1];
               
            break;
           case "onRelease1":
                trace ("onRelease1");
               
                x_mc2._x=p_evt.messageValue[0];
                x_mc2._y=p_evt.messageValue[1];
               
            break;
           
            case "onPress1":
                trace ("onPress1");
                x_mc2._x=p_evt.messageValue[0];
                x_mc2._y=p_evt.messageValue[1];
               
            break;
       
        }

}


But this code is a kinda "for dummies", cause if you have 1000 MovieClips... You know, there is no way.

Try to use an Array of MovieClips and send with the message the number of instance to define, what MC to move.


Smth like this:

tracy_obj.on...=function(){
   

    tracy_obj.coordArray[0]=this._x;
    tracy_obj.coordArray[1]=this._y;
    tracy_obj.coordArray[2]=<the number of this MC in an Array>;
    this.syncThis("onRelease1",this.coordArray);
   
    }

function syncMessageReceived(p_evt){
    trace("syncMessageReceived - fired by "+syncConnector.userID);
    trace("p_evt.messageValue="+p_evt.messageValue);
    switch(p_evt.messageType){
            case "onRelease":
                trace ("onRelease");
               
                x_mc[p_evt.messageValue[2]]._x=p_evt.messageValue[0];
                x_mc[p_evt.messageValue[2]].._y=p_evt.messageValue[1];
               
            break;
           
            case "onPress":
                trace ("onPress");
               x_mc[p_evt.messageValue[2]].._x=p_evt.messageValue[0];
               x_mc[p_evt.messageValue[2]].._y=p_evt.messageValue[1];
               
            break;
         
       
        }

}

where x_mc = Array()...

Offline

Board footer