BLOG-N-PLAY.COM
Candidates’ church chat erodes U.S. principles — chicagotribune.com — Here’s another good essay. This time about the idiotic grilling by a preacher of the two candidates in a l

TOP THREE LINKS YOU MUST CLICK ON


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.

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

ADS BY GOOGLE
LATEST ARTICLES, NEWS & POSTS
IBM has introduced new versions of two software products, part of its growing InfoSphere portfolio, that deliver information on demand to the people, processes and applications that rely on it. The new products help customers create and manage trusted information from across thei...
The SOA Consortium announced the availability of a podcast and slide deck of the presentation by K. Scott Morrison, VP of Engineering and Chief Architect at Layer 7 Technologies, on "How to Fail at SOA," recorded at the SOA Consortium meeting in Ottawa, Ontario, Canada, in June. ...
Services-Oriented Architecture (SOA) is a software architecture where functionality is grouped around business processes and packaged as interoperable services. SOA also describes IT infrastructure which allows different applications to exchange data with one another as they part...
Because of its slow growth - a factor of the freebie open source business model - Red Hat has become fodder for Wall Street acquisition speculation, BusinessWeek says, and offers VMware as a possible suitor. Such an acquisition would give VMware the operating system it's lacking,...
GoGrid announced the availability of 32-bit and 64-bit editions of Windows Server 2008 within its Cloud Computing infrastructure. Parent company ServePath is a Microsoft Gold Certified Partner, and launched Windows Server 2008 dedicated hosting in February of this year.
Symbian will release its second quarter and first half 2008 financial and operational results on 2 September. The news release will be published and distributed at 8.00 AM BST. Symbian is a software licensing company that develops and licenses Symbian OS, the open operating syste...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS

LIVE NEWS FROM THE WIRES
Pharmaceutical company Pharmaxis (ASX: PXS; Nasdaq: PXSL) today announced that the Phase 3 clinical ...
Telstra Incorporated today announced an exciting business expansion plan that will strengthen the co...
Oil export revenues earned by member countries of OPEC are set to reach a record total of over $1 tr...
Hall of Fame Baseball recipient, TOMMY LASORDA, has partnered with INDEPENDENT FILM GROUP (IFG) to p...
Pharmaxis (ASX: PXS; Nasdaq: PXSL) today announced that the first pivotal Phase 3 clinical trial of ...