Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.electrotank.vmtv.buddies
- {
- import com.electrotank.eup.Eup;
- import com.electrotank.eup.messaging.EupMessageType;
- import com.electrotank.eup.messaging.transactions.avatar.LoadAvatarsRequest;
- import com.electrotank.eup.messaging.transactions.avatar.LoadAvatarsResponse;
- import com.electrotank.logging.ILogger;
- import com.electrotank.logging.Logger;
- import com.electrotank.vmtv.entities.MtvAvatar;
- import com.electrotank.vmtv.logging.MTVLogger;
- import com.electrotank.vmtv.managers.ConnectionManager;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.utils.Dictionary;
- public class BuddyListLoader extends EventDispatcher {
- private var _eup:Eup;
- private var _list:Dictionary;
- private var _loaded:Boolean;
- private static var _logger:ILogger = Logger.getLogger('BuddyListLoader');
- /**
- * A list of all the buddies who are loaded in the form of MTVBuddy objects.
- */
- public function get buddyList():Array {
- if (!_loaded) {
- _logger.error("Buddy List Not Loaded");
- return new Array();
- }
- var budList:Array = new Array();
- for each (var mtvBud:MTVBuddy in _list) {
- budList.push(mtvBud);
- }
- return budList;
- }
- /**
- *
- */
- public function BuddyListLoader() {
- _list = new Dictionary();
- _eup = ConnectionManager.instance.electrotankUniversePlatform;
- _loaded = false;
- }
- /**
- * Push a MTV Buddy into the list.
- * @param mtvBud MTVBuddy to add to the list.
- */
- public function push( mtvBud : MTVBuddy ) : void {
- // Use the name as a key.
- _list[ mtvBud.userName ] = mtvBud;
- }
- /**
- * Loads all buddies in the list.
- */
- public function loadAllBuddies():void {
- _logger.info( 'LoadAllBuddies');
- // Create List
- var charNames:Array = new Array();
- // Pool MTV Buddy
- var mtvBud : MTVBuddy;
- // Iterate Buddy List
- for each ( mtvBud in _list ) {
- // Push Name
- charNames.push( mtvBud.userName );
- }
- // Create LoadAvatarsRequest
- var lar : LoadAvatarsRequest = new LoadAvatarsRequest();
- lar.names = charNames;
- // Send Request
- _eup.send( lar, onAvatarsLoadResponse );
- }
- private function onAvatarsLoadResponse( e : LoadAvatarsResponse ):void {
- _logger.info( 'OnLoadAvatarsResponse');
- if ( e.success ) {
- var mtvChars:Array = e.avatars;
- for (var i:uint = 0; i < mtvChars.length; i++) {
- var mtvCh:MtvAvatar = MtvAvatar(mtvChars[i]);
- if (mtvCh != null) {
- MTVBuddy(_list[ mtvCh.name ]).mtvID = int(mtvCh.getMtvUserKey());
- MTVBuddy(_list[ mtvCh.name ]).imgUrl = String(mtvCh.getAvatarImageUrl());
- MTVBuddy(_list[ mtvCh.name ]).onlineStatus = String(mtvCh.getOnlineStatus());
- }
- }
- } else {
- _logger.error( e.error.description );
- }
- _loaded = true;
- dispatchEvent(new Event(Event.COMPLETE));
- }
- }
- }
Add Comment
Please, Sign In to add comment