Code:
var key:Keyboard;
var drawer:Boolean;
var erasertool:Object;
var X;
var Y;
var nc:NetConnection;
var slot;
var line = new Object();
var drawObject:SharedObject;
var textformat:TextFormat = new TextFormat();
var activeColor:uint = 0x000000;
graphics.lineStyle(5,0x000000);
drawer = false;//to start draw
initSharedObject();
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, dodraw);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
erasertool.addEventListener(MouseEvent.CLICK, eraser);
txt.addEventListener(MouseEvent.CLICK, texto);
rect.addEventListener(MouseEvent.CLICK, recto);
cir.addEventListener(MouseEvent.CLICK, ciro);
function startDrawing(event:MouseEvent):void {
X = mou***;
Y = mouseY;
graphics.moveTo(X,Y);
drawer = true;
}
function dodraw(event:MouseEvent) {
if(this.drawer){
graphics.lineTo(mou***, mouseY);
}
}
function stopDrawing(event:MouseEvent) {
drawer = false;
line.x1 = mou***;
line.y1 = mouseY;
line.x2 = mou***;
line.y2 = mouseY;
slot = "line_" + X + "-" + Y + "X" + mou*** + "-" + mouseY;
drawObject.data[slot] = line;
}
function eraser(event:MouseEvent){
var blank = new Sprite;
var erasertool = new Object;
graphics.beginFill(0xFFFFFF);
graphics.drawRect(0, 0, stage.width, stage.height);
graphics.endFill();
drawObject.data[blank] = erasertool;
nc.call("l", erasertool);
addChild(blank);
drawer = false;
}
function texto(event:MouseEvent){
var textfield = new TextField();
var texttool = new Object;
textfield.type = TextFieldType.INPUT;
textfield.autoSize = TextFieldAutoSize.LEFT;
textfield.selectable = false;
textfield.defaultTextFormat = textformat;
textfield.textColor = activeColor;
textfield.x = mou***;
textfield.x = 250;
textfield.y = mouseY;
textfield.y = 150;
stage.focus = textfield;
drawObject.data[textfield] = texttool;
nc.call("c", texttool);
stage.addChild(textfield);
}
function recto(event:MouseEvent){
var c = new Shape;
var fa = new Object;
graphics.beginFill(0xFFFFFF);
graphics.drawRect(30, 40, 70, 75);
graphics.endFill();
drawObject.data[c] = fa;
nc.call("b", fa);
addChild(c);
drawer = false;
}
function ciro(event:MouseEvent){
var k = new Shape;
var circletool = new Object;
graphics.beginFill(0xFFFFFF);
graphics.drawCircle(stage.width, stage.height,100);
graphics.endFill();
drawObject.data[k] = circletool;
nc.call("a", circletool);
addChild(k);
drawer = false;
}
function initSharedObject() {
var nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS , onConnection);
function onConnection(event:NetStatusEvent) {
trace(event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
drawObject = SharedObject.getRemote("user2", nc.uri, true);
drawObject.connect(nc);
drawObject.addEventListener(SyncEvent.SYNC, syncit);
function syncit(event:SyncEvent) {
for (var n:String in event) {
var line = this.data[event[n].name];
graphics.moveTo(line.x1, line.y1);
graphics.lineTo(line.x2, line.y2);
}
}
}
}
nc.connect("rtmp://192.168.0.1/draw");
}
and the server side for draw class:
application.onAppStart = function()
{
trace("The deux is out of the deck");
this.drawObject = sharedObject.getRemote("user2", true);
};
application.onConnect = function(currentClient){
this.drawObject.send("user2",x,y);
}
currentClient.user2 = function(x,y){
this.drawObject.lineTo(mou***,mouseY);
}
currentClient.user2 = function(x,y){
this.drawObject.moveTo(mou***, mouseY);
}
currentClient.b = function(){
this.drawObject.drawRect(30,40,70,75);
}
currentClient.a = function(){
this.drawobject.drawCircle(stage.width, stage.height, 100);
}
currentClient.l = function(){
this.drawObject.drawRect(0,0, stage.width, stage.height);
}
currentClient.c = function(){
this.drawObject.send("c");
}
}
application.onDisconnect = function(currentClient)
{
trace("disconnect: "+currentClient.name);
this.drawObject.setProperty(currentClient.name, null);
};
Bookmarks