Comments
Patrick Collands wrote: collands (AT) gmail com I'd be very grateful for an invitation. Thank you.
Cloud Expo on Google News

SYS-CON.TV

2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Click For 2008 West
Event Webcasts
How Flash Communication Server is Helping the Multiplayer Game Industry
A Model for Dealing with the Flash Communication Server in Director

Step #3:
Now, we must connect to server. This part is very similar in Flash and Director. We must pass a RTMP url and an instance name to the Connect method. In this example room01 is an instance name for our connection. We use instance names in applications that hold several simultaneous connections (a multi-room chat for example).

In Flash:


client_nc.Connect("rtmp://localhost/
myProjectDirectory/room01");

In Director:


pNetConn.Connect("rtmp://localhost/
myProjectDirectory/room01")

Step #4:
Now it's getting fun! To create the remote shared object for our text sharing we use the "getRemote" method of SharedObject. The first parameter of the getRemote method is an object name. client_nc.uri is the URI of the NetConnection. The shared object will use it to connect to the server. The third parameter is a Boolean that indicates whether our shared object is persistent on the server or not. If we set it to true our remote shared object saves its value, thus other users that connect later receive the last value of the shared object from the server. Its value remains even when all users disconnect from server. In this sample we don't want our text to be persistent to the server. Next to this line of code we connect our created shared object to NetConnection that was constructed earlier.

In Flash:


text_so = SharedObject.getRemote("sharedText", client_nc.
uri , false);
text_so.connect(client_nc);

To create a shared object in director we must first get the SharedObject binding from Flash into a variable and then use it. The getVariable function helps us to do so. We use false for second parameter as "returnValueOrReference", because we want to get an object of Flash not its value.

In Director:


mySharedObject = pSprite.getVariable
("SharedObject", false)
text_so = mySharedObject.getRemote("sharedText", pNetConn.
uri. false);
text_so.connect(pNetConn)

Step #5:
When something changes in the shared object, the server sends a synchronization message and an onSync handler change the information on client movie. This way when a user changes a property assigned to a remote shared object, with the help of this onSync handler, all connected users could see those changes.

The "list" parameter is an array that contains information about changes in our textbox. When a user changes a remote shared object by typing a character in textbox with instance name "TypingStage", the server sends a message and onSync handler trigger on all client's machines. "list" array has two properties, name and code. If any change occurs, the code property is set to "change" and when the changes assign to our textbox this property is set to "success". Any change adds an entry in the list array. Thus, when onSync handler triggers, we must test the "list" array to find out any entry with "change" value and if so, update our textbox.

This handler is implemented with "function literal" method again, in Flash.

In Flash:


text_so.onSync = function(list){
for (var i=0; i<list.length; i++){
if (list[1].name == "textValue"
&& list[i].code != "success") {
TypingStage.text = text_so.data.
textValue;
Break;
}
}
};

Again, we use setCallBack to implement this code.

In Director:


pSprite.setCallBack(text_so,
"onSync", #mySyncTexts, me)
on mySyncTexts (me, this, aList)
repeat with i=0 to (i<aList.length)
if (aList[i].name = "textValue" AND
aList[i].code <> "success") then
member("dirTypingStage").text =
text_so.data.textValue
exit repeat
end if
end repeat
end

Step #6:
What happens when you type a character in the "dirTypingStage" textbox? You change a textbox property and this change must be seen by other users, therefore, remote shared objects should update. This is very straightforward in Flash by using the "onChanged" event of the Flash textbox object, but in Director the story is a bit different.

In Flash:


TypingStage.onChanged = function(){
text_so.data.textValue = TypingStage.
text;
};

In Director, we have two methods to implement this equivalent of the block of code above. The first method that I prefer for this sample is to use "the keyUpScript" in the "on StartMovie" handler. We tell Director that whenever a keyUp event has occurred, trigger the "textChanged" handler that is assigned to "the keyUpScript". Remember that the "keyUpScript" and "textChanged" handler must defined in a movie script. The second useful method when we have several textboxes or fields, is to assign an "on keyUp" handler to the textbox itself as a behavior script. In this way when a user types in textboxes other than the "dirTypingStage" textbox, there is not any assignment to remote shared. But in the former method any typing from user in any textbox in the stage causes the call of "onSync" handler from the server.

In Director:


on StartMovie
the keyUpScript = "textChanged"
end
on textChanged
text_so.data.textValue =
member("dirTypingStage").text
end

The complete listings of this sample are shown in Listings 1 & 2. After publishing your completed project you can test it and see the result. Run your ".htm" file twice and while typing in the textbox at one of them, see the other textbox. If you built a custom textbox that does something like a text editor for a foreign language character sets, there is no need to build same custom textbox from the beginning in Flash to work with FlashCom. The solution is to use FlashCom inside Director!

Sample Two - (Shared Ball)
In this sample we want to create a shared ball (2D circle sprite) so that any users visiting our Shockwave page can change the position of the ball with their mouse, while other users see that ball moving on the stage. This is a technique that is used at a higher level in several multi-player games.

Steps 1 and 2 are the same as previous sample, step 3 and 4 are very similar, but with small exceptions. In step 3 we use a new path as RTMP url and in step 4 we use "ball_so" as the name of our shared object and use "position" as the first parameter of getRemote method.

Step #5:
We must now write an onSync handler. When a user changes the position of the ball, this changes what is stored in the x and y properties of our sharedObject. Data must be assigned to the ball sprite location properties (or ball movieClip in Flash), on the other client's movie. When this is done, all users see the repositioning of the ball at the same time.

In Flash:


ball_so.onSync = function(list) {
sharedBall_mc._x = ball_so.data.x;
sahredBall_mc._y = ball_so.data.y;
end

In Director:


pSprite.serCallBack(ball_so,
"onSync", #mySyncBall, me)
on mySyncBall me, this, aList
sprite("Ball").LocH = ball_so.data.x
sprite("Ball").LocV = ball_so.data.y
end

Step #6:
When a user changes the ball position with their mouse, this change must be assigned to x and y properties of "ball_so.data". When those properties are changed, the server sends a synchronization message and our "onSync" handler triggers the other users' machines. This code in Flash is implemented in the "onPress" handler of the ball movieClip but for the best performance in Director, we implement it on "exitframe" handler of a frame behavior, using traditional Director-style event handling.

In addition to setting the x and y properties of shared object, we must ensure that the user does not move ball out of the stage boundaries. Therefore, if our stage size is 640 by 480, we test the position of the ball and if it is 50 pixels (depending on the size of the ball) out of the stage boundaries, we move it back into the stage.

In Flash:


sharedBall_mc.onPress =
function(){
this.onMouseMove =
function(){
ball_so.data.x = this._x =
_root._xmouse;
ball_so.data.y = this._y =
_root._ymouse;
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;
}
};
sharedBall_mc.onRelease = sharedBall_
mc.onReleaseOutSide = function()
delete this.onMouseMove;
};
About Nima Azimi
Nima Azimi is a software engineer, multimedia project manager,
consultant and programmer on variety projects. His projects include
educational "How does it works" titles for children education with
real-time 3D content. He has worked with Director for over four years,
and he currently teaches courses in Director programming and multimedia.
In his spare time he makes highly detailed photorealistic 3D scenes as a
3D artist and writes video game scripts and gameplay ideas that he
wishes to develop into full games at within the near future.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Just a note: with the new release this month it will not be FlashComm or Flash Communication Server. The beta has it anounced as Flash Media Server 2.

|| Using authentication, you could give different users different roles in the system, assigning some users more power in the system than others ||

I've tried this. It works real well.


Your Feedback
Rob Sandie wrote: Just a note: with the new release this month it will not be FlashComm or Flash Communication Server. The beta has it anounced as Flash Media Server 2.
gamer4all wrote: || Using authentication, you could give different users different roles in the system, assigning some users more power in the system than others || I've tried this. It works real well.
Latest Cloud Developer Stories
The Enterprise Cloud Requires a real time infrastructure and a management discipline that understands and can enforce service level discipline.
CloudBench Applications, Inc. announced its financial results for the three months and nine months ending September 30, 2009. All amounts are stated in Canadian dollars unless otherwise noted. Revenues from BasicGov, the Company's cloud computing solution for local government, gr...
The new contract is an industry first, with CSC being the first Microsoft partner to lead and win a cloud computing services agreement of this scale. Under terms of the contract, CSC will provide Royal Mail Group's 30,000 employees with access to new IT services using Microsoft's...
Operates in over 170 countries and is one of the world’s leading providers of communications solutions and services. Richard Tarboton talks for MeettheBoss.TV on his role as Head of Energy & Carbon for BT and what they are doing towards reducing carbon emissions.
CA is going to put its Agile Planner software on salesforce.com’s Force.com platform in the first half to accelerate development time and give users visibility over their development initiatives to reduce time-to-market. Customers are supposed to be able to accelerate the deploym...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News
CloudBench Applications, Inc. announced its financial results for the three months and nine months e...