views:

68

answers:

2

I am building a shared whiteboard and I cannot get the shared whiteboard to be shared. I have successfully created a shared method and I see the shared object in the Admin Console that it is there and connected but can't see the drawing on a different browser. I am posting the entire actionscript code. Please help me if you can. Will be greatly appreciated. I am really new to actionscript.

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

 public class PenSOmc extends Sprite
 {
  private var drawing_so:SharedObject;
  private var nc:NetConnection;
  private var good:Boolean;
  private var isDrawing:Boolean;
  private var penMC:MovieClip;
  private var rpenMC:MovieClip;
    // Mouse Coordinates
    private var startX:int;
    private var startY:int;
    private var endX:int;
    private var endY:int;

  // Remote mouse coordinates
    private var rstartX:int;
    private var rstartY:int;
    private var rendX:int;
    private var rendY:int;


  public function PenSOmc ()
  {
   penMC = new MovieClip();
   var rtmpNow:String="rtmp://localhost/whiteboard";
   nc=new NetConnection;
   nc.connect(rtmpNow);
   nc.addEventListener(NetStatusEvent.NET_STATUS,doSO);
   stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
   stage.addEventListener(MouseEvent.MOUSE_MOVE, drawing);
   stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
   addChild(penMC);
  }


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

  private function doUpdate (se:SyncEvent):void
  {

   for (var cl:int = 0; cl < se.changeList.length; cl++)
   {    


    trace(se.changeList[cl].code);

    switch(se.changeList[cl].code)
    {
     case "clear":
      break;
     case "success":
      break;
     case "change":
      //var points:String = sharedObject.data.points;


      var pointsArray:Array = drawing_so.data.points.split(/,/);
      var rstartX:int = int(pointsArray[0]);
      var rstartY:int = int(pointsArray[1]);
      var rendX:int = int(pointsArray[2]);
      var rendY:int = int(pointsArray[3]);   
      rpenMC = new MovieClip();
      rpenMC.graphics.moveTo(rstartX,rstartY);
      rpenMC.graphics.lineTo(rendX,rendY);
      addChild(rpenMC);
      break;
    }
   }
  }

  private function startDrawing (e:MouseEvent):void
  {
   trace("Start drawing");
   isDrawing = true;
   var penTipSize:uint = 1;
   var penColor:Number = 0x000000;
   penMC.graphics.lineStyle(penTipSize, penColor, 1.0);
   startX = mouseX;
   startY = mouseY;
   penMC.graphics.moveTo(startX, startY);
  }

  private function stopDrawing (e:MouseEvent):void
  {
   trace("Stop drawing");
   isDrawing = false;
  }

  private function drawing (e:MouseEvent):void
  {
   if (isDrawing)
   {
    trace("Drawing");
    endX = mouseX;
    endY = mouseY;
    drawing_so.setProperty("points",startX + "," + startY + "," + endX + "," + endY);
    penMC.graphics.lineTo(endX, endY);
   }
  }

 }

}
A: 

Hi

try to change this:

drawing_so = SharedObject.getRemote("draw",nc.uri,false);

to

drawing_so = SharedObject.getRemote("draw",nc.uri,true);

Thank you. Eugene

Eugene
Eugene
This is not the solution. True or false only relates to whether it is persistent or not persistent. That is whether when you close the application you can still come back and find drawings on the board depending on if others remained connected to the application.
play
I know that, but i heard that it could help, anyway do you have some exception output or trace?did you debug your code?what did you see there inside of SO object?
Eugene
Please see my update. It is now a shared whiteboard with one problem.
play
A: 

I have now made it a shared whiteboard by adding the following correction:

  rpenMC = new MovieClip();
  var rpenTipSize:uint = 4;
  var rpenColor:Number = 0x000000;
  rpenMC.graphics.lineStyle(rpenTipSize, rpenColor, 1.0);

But there is still one problem. The sharedobject doesn't update fast enough for the lines drawn to really be lines. They are dotted lines instead because some data is skipped as the sharedobject is updated in intervals. I used drawing_so.fps = 0 to set the frame rate but it is still not fast enough from on the browser. It is only fast enough on the flash test client to the server. I'm in the process of trying to figure out a better way.

play
Can you intercept coordinates of points and connect them with lines?
alxx
I'm not sure how to do that.
play
Do you know how to do that? Is it possible? I'm not sure. Was that a suggestion or question?
play