
Chapter 3 38
5 When you get a shared object, make sure you connect it to the NetConnection object.
// Connect to the shared object
ball_so.connect(client_nc);
6
Create the function that updates the shared object data with the position of the ball.
// Manipulate the ball
SharedBall_mc.onPress = function() {
this.onMouseMove = function() {
ball_so.data.x = this._x = _root._xmouse;
ball_so.data.y = this._y = _root._ymouse;
// Constrain the ball to the stage
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;
}
};
};
7
When the user releases the ball, remove the hold on it.
// Release control of the ball
SharedBall_mc.onRelease = SharedBall_mc.onReleaseOutside=function () {
delete this.onMouseMove;
};
To test your sample application:
1 In the Flash MX authoring environment, after you have saved your work, publish it by
selecting File > Publish.
2 Open two instances of the SWF file in the application directory.
3 Move the ball in one instance to see the other immediately updated.
Sample 4: Hello Server
This sample is the first to use server-side ActionScript. In it, you write your client-side
ActionScript in Macromedia Flash MX. Then, you write a corresponding function in server-side
ActionScript that you store in a main.asc file. First, however, you begin with the user interface.
About the sample
The user opens the doc_hello.swf file, enters a name, and gets a message back from the server that
includes the user’s name.
Re-creating the sample
The doc_hello.fla file provides the ActionScript for sending information from the server to the
client.
See “Creating your working environment” on page 31 before you start to re-create the sample.
Kommentare zu diesen Handbüchern