Server-side ActionScript Notes


/ Published in: ActionScript
Save to your folder(s)

These are the standard event handlers for a new Application using the FMS.


Copy this code and paste it in your HTML
  1. /*
  2. Between the time an instance is created and destroyed, a number of things can happen. To simplify how things work, they are divided into three sections: startup, midlife, and shutdown.
  3.  
  4. Each application object is a singleton object. Each instance gets it's own application object which is an instance of the Application class.
  5.  
  6. These are all the standard event handler method of the application object
  7. */
  8.  
  9. /***************************
  10. Startup
  11. ***************************/
  12. application.onAppStart = function ( ) {
  13. //A. onAppStart is where to Initialize counters, variables, id's, etc
  14. trace( "onAppStart> " + application.name + " is starting at " + new Date() );
  15.  
  16. //B. You can set up a Server-side shared object to synchronize clients
  17. this.so = SharedObject.get(application.name + ".com", true);
  18.  
  19. //C. This is the proper way to set default variables. It allows for expansion
  20. if(this.so.getProperty("t" == undefined)){}
  21. if(this.so.getProperty("foo" == undefined)){}
  22.  
  23. //Always assign unique ID's on the Server-Side because it's single threaded
  24. this.nextUserId = 0;
  25. };
  26. application.onStatus = function (info) {
  27. trace("onStatus> info.level: " + info.level + ", info.code: " + info.code);
  28. trace("onStatus> info.description: " + info.description);
  29. trace("onStatus> info.details: " + info.details);
  30. };
  31. application.onConnect = function (p_client, userName, password) {
  32. //A. Assign a uniqueID for any user who logs in
  33. //p_client.userId = this.nextUserId++;
  34.  
  35. //B. Decide is a client needs a userName
  36. p_client.userName = userName;
  37.  
  38. //C. Decide is you want to give a client user read/write access
  39. //p_client.writeAccess = "/public";
  40. //p_client.readAccess = "/";
  41.  
  42. //D. Inform the user that they have made a success connection
  43. application.acceptConnection(p_client);
  44.  
  45. trace("onConnect> client.ip: " + p_client.ip);
  46. trace("onConnect> client.agent: " + p_client.agent);
  47. trace("onConnect> client.referrer: " + p_client.referrer);
  48. trace("onConnect> client.protocol: " + p_client.protocol);
  49. };
  50. application.onDisconnect = function (p_client) {
  51. //A. Clear any session variables that may pertain to a client user (SharedObject variables)
  52. trace("onDisconnect> client.userName: " + p_client.userName)
  53. trace("onDisconnect> disconnecting at: " + new Date( ));
  54. };
  55. /***************************
  56. Shutdown
  57. ***************************/
  58. application.onAppStop = function (info) {
  59. //A. For when the app stops
  60. trace("onAppStop> application.name: " + application.name);
  61. trace("onAppStop> stopping at " + new Date( ));
  62. trace("onAppStop> info.level: " + info.level);
  63. trace("onAppStop> info.code: " + info.code);
  64. trace("onAppStop> info.description: " + info.description);
  65. };
  66. /***************************
  67. MidLife
  68. ***************************/
  69. /*
  70. Below are methods that any client can call. You are also able to write such methods within onConnect like:
  71.  
  72. ///////////////////////////////////////////////////
  73. application.onConnect = function(p_client){
  74. p_client.changeText = function(p_client){
  75. //Do Something
  76. }
  77. }
  78. ///////////////////////////////////////////////////
  79.  
  80. The reason you may not want to do this is because every time a user connects, this function will be placed into memory. Therefore if many users connect, you could begin to fing issues with memory allocation so it's much more efficient to use the psuedo Javascript Class called prototype.
  81. */
  82. Client.prototype.changeText = function(p_client){
  83.  
  84. }
  85. Client.prototype.getStreamLength = function(p_streamName) {
  86. trace("Stream.length: " + p_streamName + ", " + Stream.length(p_streamName));
  87. return Stream.length(p_streamName);
  88. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.