PageRenderTime 61ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/Games/GirlSwordFlash/src/mochi/as3/MochiSocial.as

http://flaswf.googlecode.com/
ActionScript | 213 lines | 112 code | 27 blank | 74 comment | 3 complexity | 4a31c70e310d8b407d68980ea524ed71 MD5 | raw file
  1. /**
  2. * MochiServices
  3. * Class that provides API access to Mochi Social Service
  4. * @author Mochi Media
  5. */
  6. package mochi.as3 {
  7. import flash.display.Sprite;
  8. public class MochiSocial {
  9. public static const LOGGED_IN:String = "LoggedIn";
  10. public static const LOGGED_OUT:String = "LoggedOut";
  11. public static const LOGIN_SHOW:String = "LoginShow";
  12. public static const LOGIN_HIDE:String = "LoginHide";
  13. public static const LOGIN_SHOWN:String = "LoginShown";
  14. public static const PROFILE_SHOW:String = "ProfileShow";
  15. public static const PROFILE_HIDE:String = "ProfileHide";
  16. public static const PROPERTIES_SAVED:String = "PropertySaved";
  17. public static const WIDGET_LOADED:String = "WidgetLoaded";
  18. public static const FRIEND_LIST:String = "FriendsList";
  19. public static const PROFILE_DATA:String = "ProfileData";
  20. public static const GAMEPLAY_DATA:String = "GameplayData";
  21. public static const ACTION_CANCELED:String = "onCancel";
  22. public static const ACTION_COMPLETE:String = "onComplete";
  23. // initiated with getUserInfo() call.
  24. // event pass object with user info.
  25. // {name: "name", uid: unique_identifier, profileImgURL: url_of_player_image, hasCoins: True}
  26. public static const USER_INFO:String = "UserInfo";
  27. public static const ERROR:String = "Error";
  28. // error types
  29. public static const IO_ERROR:String = "IOError";
  30. public static const NO_USER:String = "NoUser";
  31. public static const PROPERTIES_SIZE:String = "PropertiesSize"
  32. private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
  33. public static var _user_info:Object = null;
  34. public static function getVersion():String
  35. {
  36. return MochiServices.getVersion();
  37. }
  38. public static function getAPIURL():String
  39. {
  40. if (!_user_info) return null;
  41. return _user_info.api_url;
  42. }
  43. public static function getAPIToken():String
  44. {
  45. if (!_user_info) return null;
  46. return _user_info.api_token;
  47. }
  48. // Hook default event listener behavior
  49. {
  50. MochiSocial.addEventListener( MochiSocial.LOGGED_IN, function(args:Object):void {
  51. _user_info = args;
  52. } );
  53. MochiSocial.addEventListener( MochiSocial.LOGGED_OUT, function(args:Object):void {
  54. _user_info = null;
  55. } );
  56. }
  57. /**
  58. * Method: showLoginWidget
  59. * Displays the MochiGames Login widget.
  60. * @param options object containing variables representing the changeable parameters <see: GUI Options>
  61. * {x: 150, y: 10}
  62. */
  63. public static function showLoginWidget(options:Object = null):void
  64. {
  65. MochiServices.setContainer();
  66. MochiServices.bringToTop();
  67. MochiServices.send("social_showLoginWidget", { options: options });
  68. }
  69. public static function hideLoginWidget():void
  70. {
  71. MochiServices.send("social_hideLoginWidget");
  72. }
  73. public static function requestLogin(properties:Object = null):void
  74. {
  75. MochiServices.setContainer();
  76. MochiServices.bringToTop();
  77. MochiServices.send("social_requestLogin", properties);
  78. }
  79. public static function showProfile(options:Object = null):void
  80. {
  81. MochiServices.setContainer();
  82. MochiServices.stayOnTop();
  83. MochiServices.send("social_showProfile", options );
  84. }
  85. public static function saveUserProperties(properties:Object):void
  86. {
  87. MochiServices.send("social_saveUserProperties", properties);
  88. }
  89. /**
  90. * Method: getFriendsList
  91. * Asyncronously request friend graph
  92. * Response returned in MochiSocial.FRIEND_LIST event
  93. */
  94. public static function getFriendsList(properties:Object = null):void
  95. {
  96. MochiServices.send("social_getFriendsList",properties);
  97. }
  98. // <--- BEGIN MochiSocial experimental calls ---
  99. /**
  100. * Method: getProfileData
  101. * Asyncronously request mochigames user profile data (non-game specific)
  102. * @param properties Object containing user information
  103. * Response returned in MochiSocial.PROFILE_DATA event
  104. * { uid: 'user_id' }
  105. */
  106. /*
  107. public static function getProfileData(properties:Object = null):void
  108. {
  109. MochiServices.send("social_getProfileData", properties);
  110. }
  111. */
  112. /**
  113. * Method: getGameplayData
  114. * Asyncronously request mochigames user gameplay data (game specific)
  115. * @param properties Object containing user and game information
  116. * Response returned in MochiSocial.GAMEPLAY_DATA event
  117. * { uid: 'user_id', gameID: 'xxx' }
  118. */
  119. /*
  120. public static function getGameplayData(properties:Object = null):void
  121. {
  122. MochiServices.send("social_getGameplayData", properties);
  123. }
  124. */
  125. // --- END MochiSocial experimental calls --->
  126. /**
  127. * Method: postToStream
  128. * Post (optionally with a reward) a message to user's public stream. The stream post goes both on MochiGames as well as their other social networks.
  129. * Item id's must be marked as 'giftable' in your developer account.
  130. * Items are given as a reward only to the current player as incentive for posting about the game.
  131. * @param properties Object containing message
  132. * { channel: 'xxx', item: 'xxx', title: 'xxx', message: 'xxx' }
  133. */
  134. public static function postToStream(properties:Object = null):void
  135. {
  136. MochiServices.setContainer();
  137. MochiServices.bringToTop();
  138. MochiServices.send("social_postToStream", properties);
  139. }
  140. /**
  141. * Method: inviteFriends
  142. * Post (optionally with a gift) invite to friends
  143. * also may include prepopulated list of friends. Item id's must be marked as giftable in your developer account.
  144. * Each invited player and the current player will be given the gifted item.
  145. * @param properties Object containing message
  146. * { friends: ['xxx'], item: 'xxx', title: 'xxx', message: 'xxx' }
  147. */
  148. public static function inviteFriends(properties:Object = null):void
  149. {
  150. MochiServices.setContainer();
  151. MochiServices.bringToTop();
  152. MochiServices.send("social_inviteFriends", properties);
  153. }
  154. /**
  155. * Method: requestFan
  156. * Ask the current player to become a fan and follow your developer updates.
  157. * Your messages are recieved by players both through MochiGames.com and in-game via the login widget or leaderboards.
  158. * You can configure your update settings on mochimedia.com
  159. * @param properties Object containing message
  160. * { channel: 'xxx' }
  161. */
  162. public static function requestFan(properties:Object = null):void
  163. {
  164. MochiServices.setContainer();
  165. MochiServices.bringToTop();
  166. MochiServices.send("social_requestFan", properties);
  167. }
  168. // --- Callback system ----------
  169. public static function addEventListener( eventType:String, delegate:Function ):void
  170. {
  171. _dispatcher.addEventListener( eventType, delegate );
  172. }
  173. public static function get loggedIn():Boolean
  174. {
  175. return _user_info != null;
  176. }
  177. public static function triggerEvent( eventType:String, args:Object ):void
  178. {
  179. _dispatcher.triggerEvent( eventType, args );
  180. }
  181. public static function removeEventListener( eventType:String, delegate:Function ):void
  182. {
  183. _dispatcher.removeEventListener( eventType, delegate );
  184. }
  185. }
  186. }