YOUR FEEDBACK
José D'Andrade wrote: "...it may never be released..." Why? "...if Midori isn’t heir to Windows Mi...


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
MXDJ TOP 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.

YOUR FEEDBACK
NN wrote: No it is not a concern. If they are thinking people are not waiting for site to load and run away. It is myth because HTML page also takes time to load apart from home page loads little faster compare to web 2.0 home page. HTML base site won't make your site popular overnight or get 1 million order on first day. I like what I show and thought wow someone made e-commerce site and that also looks and perform better compare to HTML wants to switch back... I know PHP might perform better but looks and easy of using site if you come back next time will be way way fast. You can switch back unless you will get traffic like ebay or amazon otherwise you are fine in performance wise.
Peter De Ranter wrote: Hi, We created www.cotswoldoutdoor.com as a technology provider (not designed it). The customer is doubting that consumers don't wait for the LOADING of the site. Is this a concern ? They even think of switching back to html.
Brian wrote: I think we're heading in the right direction, but we've still got some work to do. Search engine support, for example, is something that is still a big problem for RIAs.
j j wrote: With all the noise the Web 2.0 revolutionaries are making, it's easy to ignore another-this time velvet-revolution. E-commerce 2.0 is coming into maturity and getting ready to relieve its now 10+ year old predecessor. It's about time.
LATEST FLEX STORIES & POSTS
Vaulthouse has launched its flagship product aimed at companies that deal with insurance claims. ClaimAble is an innovative claims management solution based on the Adobe AIR framework, enabling a desktop-like experience to be delivered over the web.
I recently gave a presentation on Flex frameworks at the New York Flex Users Group. More than 50 people showed up, which proves that this is an important topic. By the end of the presentation the temperature in the room had increased because an innocent talk had turned into a heated di...
Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec...
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be...
4D announced the release of 4D Web 2.0 Pack v11 Release 2. The new version, a combination of two products - 4D AJAX Framework and 4D for Flex - brings a powerful set of tools, plug-ins, and components that allow 4D developers to harness the power of Web 2.0 technologies, and deliver li...
Read about Forrester's findings on RIA security included in a Forrester Research paper valued at $775 titled 'Securing Rich Internet Applications' by Jeffrey Hammond, plus find out about Curl's Security Architecture in a new Curl white paper titled 'Developing Secure Rich Internet Appl...
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

MOST READ THIS WEEK
ADS BY GOOGLE