|
FCS SharedObject Example via RTMP
|
 |
This example demonstrates the file structure required for a SharedObject in Flash Communications Server. Use this as a guide to making additional shared objects. This example creates a simple web counter in Flash. Below is the ActionScript for frame 1 of your script. All that's required on the main stage is a dynamic text box called "displayText". Place a dynamic text box on the stage and name the variable "displayText". Publish and test your movie. The first time you run it you see the number 1. Reload the swf and it says 2. Reload again and it says 3. You'll have to guess what happens if you load it again.
Since we set our third getRemote parameter to true, the counter value will persist on the server.
myNC = new NetConnection();
myNC.connect("rtmp://66.216.97.115/UserName/cnt");
mySO = SharedObject.getRemote("counter",myNC.uri,true);
mySO.connect(myNC);
myNC.onStatus = function(info) {
trace("Level: " + info.level + newline + "Code: " + info.code+":");
}
mySO.onSync = function(sync) {
goUp();
}
function goUp(){
mySO.data.count = (mySO.data.count*1)+1;
displayText = mySO.data.count;
ad++;
if (ad > 1){mySO.close();}
}
Publish and run this example movie twice. When you do so, FCS creates a folder in your main FTP folder called "sharedobjects". Inside of the sharedobjects folder is another folder called "cnt". Inside of "cnt" is a data file called "counter.fso". This file and the folder's mentioned are automatically created by FCS when you run the app the first time.
|