[AS3] Cannot sync sharedObjects
Hello, Ive tried converting the SharedObject tutorial [http://www.adobe.com/devnet/flashmediaserver/sample_apps.html] provided by Adobe from AS2 to AS3. When one client moves the ball, the other client should be able to see the ball moving on another swf, and vice versa.
The AS2 one worked fine with my flash media server 3.5 and wampp server on.
When I tried the AS3 one, the sharedObject cannot sync, even though the connection was successful and the sharedObject "position" was created in the server. Can anyone help me solve the problem?
stop();
var nc:NetConnection = new NetConnection();
nc.connect("rtmp://localhost/myapplication");
//check whether connection is successful
nc.addEventListener(NetStatusEvent.NET_STATUS, onstatus1);
function onstatus1 (event:NetStatusEvent): void
{
trace("Level: " + event.info.level + "\nCode: " + event.info.code);
}
//create and connect the sharedObject
var ball_so = SharedObject.getRemote("position", nc.uri, false);
ball_so.connect(nc);
//onSync function
nc.addEventListener(SyncEvent.SYNC, syncSO);
function syncSO(event:SyncEvent):void
{
SharedBall_mc.x = ball_so.data.x;
SharedBall_mc.y = ball_so.data.y;
}
//event listeners for the dragging events
SharedBall_mc.addEventListener(MouseEvent.MOUSE_DOWN, ballStartDrag);
SharedBall_mc.addEventListener(MouseEvent.MOUSE_UP, ballEndDrag);
SharedBall_mc.addEventListener(Event.ENTER_FRAME, ballShadow);
//start drag function
function ballStartDrag(event:MouseEvent):void
{
SharedBall_mc.startDrag();
//setting the constraints
if (SharedBall_mc.x>=stage.width) {
SharedBall_mc.x = stage.width - 50;
}
if (SharedBall_mc.x <=0) {
SharedBall_mc.x = 50;
}
if (SharedBall_mc.y>=stage.height) {
SharedBall_mc.y = stage.height - 50;
}
if (SharedBall_mc.y<=0) {
SharedBall_mc.y = 50;
}
}
//when the dragging ends
function ballEndDrag(event:MouseEvent):void{
SharedBall_mc.stopDrag();
}
function ballShadow (event:Event):void{
//store the x and y position of the ball into the sharedObject
ball_so.data.x = SharedBall_mc.x;
ball_so.data.y = SharedBall_mc.y;
//make the shadow follow the ball
Shadow_mc.x = SharedBall_mc.x+15+(-1*SharedBall_mc.y+400)/4;
Shadow_mc.y = SharedBall_mc.y/2+220;
Shadow_mc.alpha = (SharedBall_mc.y+400)/16;
}
