0 Replies Latest reply on Nov 10, 2009 6:25 AM by Ermello_78

    How can I set up and move two movie clip around the stage with remote shared object?

    Ermello_78 Level 1

      Hi, I have a problem.

      I need to move two movie clip around the stage...

      I wrote this script:

       

      package
      {
        import flash.display.Sprite;
        import flash.net.SharedObject;
        import flash.events.NetStatusEvent;
        import flash.events.SyncEvent;
        import flash.net.NetConnection;
        import flash.events.MouseEvent;
        import flash.display.MovieClip
        //import flash.net.ObjectEncoding;

       

        public class BlocchiLogici extends Sprite
        {
              private var pointer_so:SharedObject;
              private var pointer1_so:SharedObject;
              private var nc:NetConnection;
              private var good:Boolean;
              private var Cerchio:cerchio;
              private var Quadrato:quadrato;
              private var Rettangolo:rettangolo;
              private var Triangolo:triangolo;

       

              public function BlocchiLogici()
              {
                   //NetConnection.defaultObjectEncoding=flash.net.ObjectEncoding.AMF0;
                   //Connect
                   var rtmpNow:String="rtmp://192.168.1.66/BlocchiLogici";
                   nc=new NetConnection  ;
                   nc.connect (rtmpNow);
                   nc.addEventListener (NetStatusEvent.NET_STATUS,doSO);
                   Cerchio=new cerchio ;
                   addChild (Cerchio);
                   Cerchio.x=50;
                   Cerchio.y=200;
                   Cerchio.addEventListener (MouseEvent.MOUSE_DOWN,beginDrag);
                   Cerchio.addEventListener (MouseEvent.MOUSE_UP,endDrag);
                   Quadrato=new quadrato ;
                   addChild (Quadrato);
                   Quadrato.x=100;
                   Quadrato.y=200;
                   Quadrato.addEventListener (MouseEvent.MOUSE_DOWN,beginDrag);
                   Quadrato.addEventListener (MouseEvent.MOUSE_UP,endDrag);
              }

       

              private function doSO (e:NetStatusEvent):void
              {
                   good=e.info.code == "NetConnection.Connect.Success";
                   if (good)
                   {
                         //Shared object
                         pointer_so=SharedObject.getRemote("point",nc.uri,false);
                         pointer_so.connect (nc);
                         pointer_so.addEventListener (SyncEvent.SYNC,doUpdate);
                   }
              }

       

              private function doUpdate (se:SyncEvent):void
              {   
                   for (var cl:uint; cl < se.changeList.length; cl++)
                       {
                         trace(se.changeList[cl].code);
                         if (se.changeList[cl].code == "change")
                         {   
                             if (Cerchio)
                          {
                              switch (se.changeList[cl].name)
                              {
                                   case "xpos" :
                                         Cerchio.x=pointer_so.data.xpos;
                                         break;
                                   case "ypos" :
                                         Cerchio.y=pointer_so.data.ypos;
                                         break;
                              }
                          }
                          else if (Quadrato)
                             {
                                 switch (se.changeList[cl].name)
                              {                   
                                   case "xpos" :
                                         Quadrato.x=pointer_so.data.xpos;
                                         break;
                                   case "ypos" :
                                         Quadrato.y=pointer_so.data.ypos;
                                         break;
                              }
                          }
                       }
                   }
              }

       

              private function beginDrag (e:MouseEvent)
              {
                  if (Cerchio)
                   {
                       Cerchio.addEventListener (MouseEvent.MOUSE_MOVE,moveMc);
                       Cerchio.startDrag ();
                   }
                  else if (Quadrato)
                   {
                       Quadrato.addEventListener (MouseEvent.MOUSE_MOVE,moveMc);
                       Quadrato.startDrag ();
                   }
              }

       

              private function endDrag (e:MouseEvent)
              {
                  if (Cerchio)
                   {
                       Cerchio.stopDrag ();
                   }
                  else if (Quadrato)
                   {
                       Quadrato.stopDrag ();
                   }
              }

       

              private function moveMc (e:MouseEvent)
              {
                  e.updateAfterEvent ();
                  if (Cerchio)
                   {
                       pointer_so.setProperty ("xpos",Cerchio.x);
                       pointer_so.setProperty ("ypos",Cerchio.y);
                   }
                  else if (Quadrato)
                   {
                       pointer_so.setProperty ("xpos",Quadrato.x);
                       pointer_so.setProperty ("ypos",Quadrato.y);
                   }
              }
        }
      }

       

      Please, help me...