Accessibility

Table of Contents

Integrating Remote Shared Objects with Flex and Flash Communication Server

Data Structure Review

An object is a collection of properties and it is one of the basic Flex data types. However, objects behave differently than numbers or strings.

For example, examine the following piece of code.

myNum1 = 5;
myNum2 = myNum1;
myNum1 = 6;

At the end of this code, myNum1 contains the number 6, and myNum2 contains the number 5; however, this same example does not hold true for objects.

If you assign one object to another, as in the following example:

myObj2 = new Object();
myObj2.test = 3;
myObj2.case = 4;
myObj1 = myObj2; 

Flex doesn’t actually make a copy of the object, but rather myOb1 contains a reference to myObj2. So, there is one copy of all the data stored in the object and both names can be used to access this data. Therefore, myObj1.test and myObj2.test are really the same variable.

This can cause an issue when you receive a new object from FCS. For example, if you receive a change for Slot 1, the intuitive approach might be to assign the data coming from the FCS shared remote object directly to your myData array using an assignment (=) operator.

However, as noted above, if you simply set two objects equal to each other, Flex will be unable to make a copy, but merely provide a new reference or way for you to access the same data. This means that any time you attempt to make a change to an element in your myData array, in reality, you are attempting to change the shared remote object that FCS created.

The implication is that every user running your application will receive a change made by a single user. When used properly this can be beneficial, however, in many cases it can cause significant performance reduction and potentially prevent users with slower connections from accessing the application.

A quick way to resolve this issue is to create a brand new object every time a new piece of content arrives from Flash Communication Server and then use that newly created object in the myData array. Any changes made from within a single client’s application will affect a user’s copy of the data but will not change values in the shared remote object used by everyone.

The final step required to display incoming data from FCS is to provide the name of the function syncData to the sync event of the component. Now, whenever data changes on the server, a sync event will be broadcast from the RemoteShared component and the syncData function will be called to process the received data.