sridhargaji
08-04-2009, 11:25 AM
I have a problem in remote shared object's data to be get synchronized with the Flash Media Server(FMS).I could connect to the FMS but the values sent are not getting synchronized with the FMS.The code is regarding the drawing with the mouse.The drawn graphics should persist even after closing the flash movie.Please help me out.
Here is the complete code, .
var drawing:Boolean;
var startX;
var startY;
var slot;
var line_obj = new Object();
var drawing_so:SharedObject;
graphics.lineStyle(5,0x000000);
drawing = false;//to start with
initSharedObject();
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
function startDrawing(event:MouseEvent):void {
//move to the correct starting position for drawing
startX = mouseX;
startY = mouseY;
graphics.moveTo( startX, startY);
drawing = true;
}
function draw(event:MouseEvent) {
if (drawing) {
graphics.lineTo(mouseX,mouseY);
}
}
function stopDrawing(event:MouseEvent) {
drawing = false;
line_obj.x1 = mouseX;
line_obj.y1 = mouseY;
line_obj.x2 = mouseX;
line_obj.y2 = mouseY;
slot = "line_" + startX + "-" + startY + "X" + mouseX + "-" + mouseY;
drawing_so.data[slot] = line_obj;
}
function initSharedObject() {
var main_nc = new NetConnection();
main_nc.addEventListener(NetStatusEvent.NET_STATUS , onConnection);
function onConnection(event:NetStatusEvent) {
trace(event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
drawing_so = SharedObject.getRemote("paint", main_nc.uri, true);
drawing_so.connect(main_nc);
drawing_so.addEventListener(SyncEvent.SYNC, syncit);
function syncit(event:SyncEvent) {
for (var n:String in event) {
var line_obj = this.data[event[n].name];
graphics.moveTo(line_obj.x1, line_obj.y1);
graphics.lineTo(line_obj.x2, line_obj.y2);
}
}
} else {
trace("ERROR: " + event.info.code);
}
}
main_nc.connect("rtmp:/paint");
}
Thanks in advance....
Here is the complete code, .
var drawing:Boolean;
var startX;
var startY;
var slot;
var line_obj = new Object();
var drawing_so:SharedObject;
graphics.lineStyle(5,0x000000);
drawing = false;//to start with
initSharedObject();
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
function startDrawing(event:MouseEvent):void {
//move to the correct starting position for drawing
startX = mouseX;
startY = mouseY;
graphics.moveTo( startX, startY);
drawing = true;
}
function draw(event:MouseEvent) {
if (drawing) {
graphics.lineTo(mouseX,mouseY);
}
}
function stopDrawing(event:MouseEvent) {
drawing = false;
line_obj.x1 = mouseX;
line_obj.y1 = mouseY;
line_obj.x2 = mouseX;
line_obj.y2 = mouseY;
slot = "line_" + startX + "-" + startY + "X" + mouseX + "-" + mouseY;
drawing_so.data[slot] = line_obj;
}
function initSharedObject() {
var main_nc = new NetConnection();
main_nc.addEventListener(NetStatusEvent.NET_STATUS , onConnection);
function onConnection(event:NetStatusEvent) {
trace(event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
drawing_so = SharedObject.getRemote("paint", main_nc.uri, true);
drawing_so.connect(main_nc);
drawing_so.addEventListener(SyncEvent.SYNC, syncit);
function syncit(event:SyncEvent) {
for (var n:String in event) {
var line_obj = this.data[event[n].name];
graphics.moveTo(line_obj.x1, line_obj.y1);
graphics.lineTo(line_obj.x2, line_obj.y2);
}
}
} else {
trace("ERROR: " + event.info.code);
}
}
main_nc.connect("rtmp:/paint");
}
Thanks in advance....