Guest User

Untitled

a guest
Jul 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. package com.electrotank.vmtv.buddies
  2. {
  3. import com.electrotank.eup.Eup;
  4. import com.electrotank.eup.messaging.EupMessageType;
  5. import com.electrotank.eup.messaging.transactions.avatar.LoadAvatarsRequest;
  6. import com.electrotank.eup.messaging.transactions.avatar.LoadAvatarsResponse;
  7. import com.electrotank.logging.ILogger;
  8. import com.electrotank.logging.Logger;
  9. import com.electrotank.vmtv.entities.MtvAvatar;
  10. import com.electrotank.vmtv.logging.MTVLogger;
  11. import com.electrotank.vmtv.managers.ConnectionManager;
  12. import flash.events.Event;
  13. import flash.events.EventDispatcher;
  14. import flash.utils.Dictionary;
  15.  
  16. public class BuddyListLoader extends EventDispatcher {
  17.  
  18. private var _eup:Eup;
  19. private var _list:Dictionary;
  20. private var _loaded:Boolean;
  21. private static var _logger:ILogger = Logger.getLogger('BuddyListLoader');
  22.  
  23. /**
  24. * A list of all the buddies who are loaded in the form of MTVBuddy objects.
  25. */
  26. public function get buddyList():Array {
  27.  
  28. if (!_loaded) {
  29. _logger.error("Buddy List Not Loaded");
  30. return new Array();
  31. }
  32.  
  33. var budList:Array = new Array();
  34.  
  35. for each (var mtvBud:MTVBuddy in _list) {
  36. budList.push(mtvBud);
  37. }
  38.  
  39. return budList;
  40. }
  41.  
  42. /**
  43. *
  44. */
  45. public function BuddyListLoader() {
  46.  
  47. _list = new Dictionary();
  48. _eup = ConnectionManager.instance.electrotankUniversePlatform;
  49. _loaded = false;
  50.  
  51. }
  52.  
  53. /**
  54. * Push a MTV Buddy into the list.
  55. * @param mtvBud MTVBuddy to add to the list.
  56. */
  57. public function push( mtvBud : MTVBuddy ) : void {
  58.  
  59. // Use the name as a key.
  60. _list[ mtvBud.userName ] = mtvBud;
  61.  
  62. }
  63.  
  64. /**
  65. * Loads all buddies in the list.
  66. */
  67. public function loadAllBuddies():void {
  68.  
  69. _logger.info( 'LoadAllBuddies');
  70.  
  71. // Create List
  72. var charNames:Array = new Array();
  73.  
  74. // Pool MTV Buddy
  75. var mtvBud : MTVBuddy;
  76.  
  77. // Iterate Buddy List
  78. for each ( mtvBud in _list ) {
  79.  
  80. // Push Name
  81. charNames.push( mtvBud.userName );
  82.  
  83. }
  84.  
  85. // Create LoadAvatarsRequest
  86. var lar : LoadAvatarsRequest = new LoadAvatarsRequest();
  87. lar.names = charNames;
  88.  
  89. // Send Request
  90. _eup.send( lar, onAvatarsLoadResponse );
  91.  
  92. }
  93.  
  94. private function onAvatarsLoadResponse( e : LoadAvatarsResponse ):void {
  95.  
  96. _logger.info( 'OnLoadAvatarsResponse');
  97. if ( e.success ) {
  98.  
  99. var mtvChars:Array = e.avatars;
  100.  
  101. for (var i:uint = 0; i < mtvChars.length; i++) {
  102.  
  103. var mtvCh:MtvAvatar = MtvAvatar(mtvChars[i]);
  104.  
  105. if (mtvCh != null) {
  106. MTVBuddy(_list[ mtvCh.name ]).mtvID = int(mtvCh.getMtvUserKey());
  107. MTVBuddy(_list[ mtvCh.name ]).imgUrl = String(mtvCh.getAvatarImageUrl());
  108. MTVBuddy(_list[ mtvCh.name ]).onlineStatus = String(mtvCh.getOnlineStatus());
  109. }
  110. }
  111.  
  112.  
  113.  
  114. } else {
  115.  
  116. _logger.error( e.error.description );
  117.  
  118. }
  119.  
  120. _loaded = true;
  121. dispatchEvent(new Event(Event.COMPLETE));
  122.  
  123. }
  124.  
  125. }
  126.  
  127. }
Add Comment
Please, Sign In to add comment