Shared Objects inside Adobe Flash Media Server
Shared Objects can be said as cookie for Flash Environment. Shared Objects are responsible for storing temporary information which can be accessible to the whole flash application. In Flash Media Server Environment, shared objects can be useful for making Chat or MultiPlayer Games Application. This article will show how we can make and store data inside Shared Objects using Adobe Flash Media Server.
application.onAppStart = function() { this.sharedobj = SharedObject.get("sharedobj", true); } application.onConnect = function(client,username) { username = "Hitesh"; trace("Client connected with username: " + username); client.username = username; // accept the connection. NOTE: normally you should add some security and/or authentication here. this.acceptConnection(client); // add the user to the SharedObject, this will trigger an onSync on all connected clients this.sharedobj.setProperty("Username", username); } // invoked whenever a client disconnects application.onDisconnect = function(client) { trace("Client disconnected."); // remove the client from the SharedOject this.chat_so.setProperty(client.username, null); }
Code Explanation:
- application.onAppStart() function will get called only once during the lifetime of the Application. This function will create a shared object by name sharedobj
- Whenever user connects to Flash Media Server Application application.onConnect() method gets called. Here we are accepting client and username from the onConnect() function. client parameter is compulsory and username is getting passed from the client application connecting to the Flash Media Server Application
- In application.onConnect() i am calling .setProperty() method of SharedObject. This method will create a “Username” key inside the shared object and will assign the username passed from the client application
- Finally application.onDisconnect() function gets called whenever user disconnects from the Flash Media Server Application. Here i am setting the key value to null which means i am destroying the content of shared object
Custom Search















