All pastes #709743 Raw Edit

Anonymous

public text v1 · immutable
#709743 ·published 2007-09-24 22:45 UTC
rendered paste body
<?xml version="1.0" encoding="utf-8"?>
<mx:Application	
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute" 
	creationComplete="onCreationComplete()" 
	currentState="login" xmlns:xmlrpc="com.ak33m.rpc.xmlrpc.*" xmlns:flexlib="http://code.google.com/p/flexlib/" creationPolicy="all">
	<xmlrpc:XMLRPCObject id="gatewayObject" endpoint="http://daniels-comp:9090/plugins/gateway/xml-rpc" />
	<mx:states>
		<mx:State name="login">
			<mx:RemoveChild target="{msg}"/>
			<mx:RemoveChild target="{button1}"/>
			<mx:AddChild position="lastChild">
				<mx:Panel width="250" height="200" layout="absolute" horizontalCenter="0" verticalCenter="0" title="Login to FlexIM">
					<mx:Label x="10" y="10" text="Username:"/>
					<mx:TextInput x="10" y="36" id="username" text="test"/>
					<mx:Label x="10" y="66" text="Password:"/>
					<mx:TextInput x="10" y="92" id="password" displayAsPassword="true" text="test"/>
					<mx:Button x="10" y="122" label="Login" click="doLogin();"/>
				</mx:Panel>
			</mx:AddChild>
			<mx:RemoveChild target="{consoleMsg}"/>
			<mx:RemoveChild target="{chatCodes}"/>
			<mx:RemoveChild target="{cbPresence}"/>
			<mx:RemoveChild target="{label1}"/>
			<mx:RemoveChild target="{button2}"/>
			<mx:RemoveChild target="{button3}"/>
			<mx:RemoveChild target="{button4}"/>
			<mx:RemoveChild target="{button5}"/>
			<mx:RemoveChild target="{button6}"/>
			<mx:RemoveChild target="{button8}"/>
			<mx:RemoveChild target="{button7}"/>
			<mx:RemoveChild target="{button10}"/>
		</mx:State>
		<mx:State name="registerAIM">
			<mx:RemoveChild target="{cbPresence}"/>
			<mx:RemoveChild target="{chatCodes}"/>
			<mx:RemoveChild target="{button2}"/>
			<mx:RemoveChild target="{label1}"/>
			<mx:RemoveChild target="{button5}"/>
			<mx:RemoveChild target="{button4}"/>
			<mx:RemoveChild target="{button3}"/>
			<mx:RemoveChild target="{msg}"/>
			<mx:RemoveChild target="{button1}"/>
			<mx:AddChild position="lastChild">
				<mx:Panel layout="absolute" right="10" left="10" top="10" bottom="10" title="Register for AIM" id="panel1">
					<mx:Button label="Home" click="currentState = '';" right="10" top="10"/>
					<mx:TextInput x="234" y="37" id="aim_username"/>
					<mx:Label x="234" y="11" text="Username:"/>
					<mx:Label x="234" y="67" text="Password:"/>
					<mx:TextInput x="234" y="93" id="aim_password" displayAsPassword="true"/>
					<mx:Button x="234" y="123" label="Register" click="registerAIM();"/>
				</mx:Panel>
			</mx:AddChild>
			<mx:SetStyle target="{consoleMsg}" name="right"/>
			<mx:SetStyle target="{consoleMsg}" name="bottom" value="10"/>
			<mx:RemoveChild target="{consoleMsg}"/>
			<mx:AddChild relativeTo="{panel1}" position="lastChild" target="{consoleMsg}"/>
			<mx:SetProperty target="{consoleMsg}" name="width" value="216"/>
		</mx:State>
		<mx:State name="pm">
			<mx:RemoveChild target="{chatCodes}"/>
			<mx:RemoveChild target="{cbPresence}"/>
			<mx:RemoveChild target="{button6}"/>
			<mx:RemoveChild target="{button7}"/>
			<mx:RemoveChild target="{button2}"/>
			<mx:RemoveChild target="{label1}"/>
			<mx:RemoveChild target="{button5}"/>
			<mx:RemoveChild target="{button4}"/>
			<mx:RemoveChild target="{button3}"/>
			<mx:AddChild position="lastChild">
				<mx:Panel layout="absolute" right="10" left="10" top="10" bottom="10" title="Private Message">
					<mx:Button x="529" y="10" label="Back" click="currentState = '';"/>
					<mx:Label x="10" y="12" text="Nick:"/>
					<mx:TextInput x="10" y="38" id="pm_nickname"/>
					<mx:Label x="10" y="124" text="Message:"/>
					<mx:TextArea x="10" y="150" width="322" height="188" id="pm_message"/>
					<mx:Button x="10" y="346" label="Send" click="sendPrivateMessage();"/>
					<mx:Label x="101" y="292" id="pm_status"/>
					<mx:Label x="10" y="68" text="Service:"/>
					<mx:ComboBox x="10" y="94" id="pm_protocol">
						<mx:dataProvider>
							<mx:Array>
								<mx:String>aim</mx:String>
								<mx:String>msn</mx:String>
							</mx:Array>
						</mx:dataProvider></mx:ComboBox>
				</mx:Panel>
			</mx:AddChild>
			<mx:RemoveChild target="{consoleMsg}"/>
			<mx:RemoveChild target="{msg}"/>
			<mx:RemoveChild target="{button1}"/>
		</mx:State>
		<mx:State name="roomBrowser"/>
		<mx:State name="startChat">
			<mx:RemoveChild target="{chatCodes}"/>
			<mx:RemoveChild target="{cbPresence}"/>
			<mx:RemoveChild target="{button6}"/>
			<mx:RemoveChild target="{label1}"/>
			<mx:RemoveChild target="{button2}"/>
			<mx:RemoveChild target="{button5}"/>
			<mx:RemoveChild target="{button7}"/>
			<mx:RemoveChild target="{consoleMsg}"/>
			<mx:RemoveChild target="{button4}"/>
			<mx:RemoveChild target="{button8}"/>
			<mx:RemoveChild target="{button3}"/>
			<mx:RemoveChild target="{msg}"/>
			<mx:RemoveChild target="{button1}"/>
			<mx:AddChild position="lastChild">
				<mx:Label x="10" y="10" text="J ID:"/>
			</mx:AddChild>
			<mx:AddChild position="lastChild">
				<mx:TextInput x="10" y="36" id="jid"/>
			</mx:AddChild>
			<mx:AddChild position="lastChild">
				<mx:Button x="10" y="66" label="Start Chat" click="startChat(jid.text);"/>
			</mx:AddChild>
			<mx:RemoveChild target="{button9}"/>
			<mx:AddChild position="lastChild">
				<mx:Button label="Back" right="10" bottom="10" click="currentState = '';"/>
			</mx:AddChild>
		</mx:State>
		<mx:State name="chatWindows">
			<mx:RemoveChild target="{chatCodes}"/>
			<mx:RemoveChild target="{cbPresence}"/>
			<mx:RemoveChild target="{button6}"/>
			<mx:RemoveChild target="{button2}"/>
			<mx:RemoveChild target="{button5}"/>
			<mx:RemoveChild target="{button7}"/>
			<mx:RemoveChild target="{consoleMsg}"/>
			<mx:RemoveChild target="{label1}"/>
			<mx:RemoveChild target="{button4}"/>
			<mx:RemoveChild target="{button3}"/>
			<mx:RemoveChild target="{button8}"/>
			<mx:RemoveChild target="{button9}"/>
			<mx:RemoveChild target="{msg}"/>
			<mx:RemoveChild target="{button1}"/>
			<mx:AddChild position="lastChild">
				<mx:Button label="Back" right="10" bottom="10" click="currentState = '';"/>
			</mx:AddChild>
			<mx:RemoveChild target="{button10}"/>
			<mx:AddChild position="lastChild">
				<mx:TabNavigator x="10" y="10" width="568" height="419" id="chatWindows1" creationPolicy="all">
				</mx:TabNavigator>
			</mx:AddChild>
		</mx:State>
	</mx:states>
<mx:Script>
	<![CDATA[
		import flexlib.containers.SuperTabNavigator;
		import org.jivesoftware.xiff.core.Browser;
		import mx.managers.PopUpManagerChildList;
		import com.popups.chatWindow;
		import mx.messaging.management.Attribute;
		import mx.controls.Text;
		import org.jivesoftware.xiff.data.Message;
		import org.jivesoftware.xiff.data.XMPPStanza;
		import mx.collections.ArrayCollection;
		import mx.rpc.xml.XMLDecoder;
		import mx.controls.Alert;
		import org.jivesoftware.xiff.im.Roster;
		import org.jivesoftware.xiff.conference.Room;
		import org.jivesoftware.xiff.events.*;
        import mx.rpc.events.FaultEvent;
	    import mx.rpc.events.ResultEvent;
		import mx.collections.ItemResponder;
        import mx.rpc.AsyncToken;
        import com.ak33m.rpc.xmlrpc.*;
        import mx.managers.PopUpManager;
        import org.jivesoftware.xiff.core.XMPPConnection;
		import com.models.UserInformation;
		import mx.containers.Canvas;
		
		
		[Bindable]
		public var roster:Roster;
		
		private var room:Room;
		
		private var browser:Browser;
		
		[Bindable]
		public var connection:XMPPConnection = new XMPPConnection();
		
		[Bindable]
		public var userInformation:UserInformation = new UserInformation;
		
		[Bindable]
		public var chatCount:int = 0;
		
		[Bindable]
		public var errorCodes:ArrayCollection = new ArrayCollection();
		
		[Bindable]
		public var presenceCodes:ArrayCollection = new ArrayCollection([{label:"Free To Chat"},{label:"Away"}]);
		
		[Bindable]
		public var buddyListdp:ArrayCollection = new ArrayCollection();
		
		public function onCreationComplete():void
		{			
			connection.useAnonymousLogin = false;
			//I'm running openFire on my daniels-comp so that's what I've set my server to
			connection.server = "daniels-comp";
			connection.addEventListener(ConnectionSuccessEvent.CONNECT_SUCCESS, handleConnectSuccess);
			connection.addEventListener(IncomingDataEvent.INCOMING_DATA, handleIncomingData);
			connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, errorHandler);
			connection.addEventListener(MessageEvent.MESSAGE, messageHandler);
			connection.addEventListener(OutgoingDataEvent.OUTGOING_DATA, handleOutgoingData);
			connection.addEventListener(LoginEvent.LOGIN, handleServerLogin);
			room = new Room(connection);
			room.setRoomJID("test@conference.daniels-comp");
			room.roomName = "test";
			room.conferenceServer = "conference.daniels-comp";
			room.addEventListener(RoomEvent.ROOM_JOIN, handleRoomJoin);
			roster = new Roster(connection);
			browser = new Browser(connection);
			msg.setFocus();
			msg.addEventListener(KeyboardEvent.KEY_UP,keyHandler);
			
		}
		private var curNum:Number = 0;
		private function addTab(lbl:String, navigator:TabNavigator, contentString:String=null, icon:Class=null):void {
			if(lbl=="") lbl = "(Untitled)";
						
			var child:Canvas = new Canvas();
			
			child.setStyle("closable", true);
			
			child.label = lbl;
			
			if(icon) {
				child.icon = icon;
			}
			
			var label:Label = new Label();
			label.text = contentString == null ? "Content for: " + lbl : contentString;
			
			child.addChild(label);
			
			navigator.addChildAt(child,0);
			
			curNum++;
		}
		
		private function keyHandler(event:KeyboardEvent):void
		{
			if(event.keyCode == 13)
			{
				room.sendMessage(msg.text);
				msg.text = "";
			}
		}
		
		private function startChat(ujid:String):void
		{
			chatCount = chatCount + 1;
			//var _chatWindow:chatWindow = new chatWindow();
			var child:Canvas = new Canvas();
			child.label = ujid;
			child.id = "chat" + chatCount;
			var tst:Label = new Label;
			tst.text = "HI!";
			child.addChild(tst);
			chatWindows1.addChild(child);
		}
		private function getRoster():void
		{
			roster.fetchRoster();
		}
		
		private function str_replace( replace_with:String, replace:String, original:String ):String
		{
			var array:Array = original.split(replace_with);
			return array.join(replace);
		}
		
		private function sendPrivateMessage():void
		{
			var nickTo:String = pm_nickname.text + "@" + pm_protocol.selectedItem.valueOf() + ".daniels-comp";
			//Alert.show(nickTo);
			var msg:Message = new Message(nickTo, null, pm_message.text, pm_message.text, Message.CHAT_TYPE, null);
			connection.send(msg);
			pm_nickname.text = "";
			pm_message.text = "";
			Alert.show("Message Sent!", "Private Message");
		}
		
		public function errorHandler(event:XIFFErrorEvent):void
		{
			var tmpObj:Object = {};
			tmpObj.errorType = event.errorType;
			tmpObj.errorCode = event.errorCode;
			tmpObj.errorCondition = str_replace("-"," ",event.errorCondition);
			tmpObj.errorMessage = event.errorMessage;
			errorCodes.addItem(tmpObj);
		}
		
		private function messageHandler(event:MessageEvent):void
		{
			consoleMsg.text = consoleMsg.text + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MESSAGE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + event.data.body + "\n\n\n\n";
		}
		
		public function getUsers():void
		{
			var xml:String = "<iq type='get'" +
							    " from='test@daniels-comp/xiff'" +
							    " to='search.daniels-comp'" +
							   " id='info1'" +
							   " xml:lang='en'>" +
							  " <query xmlns='jabber:iq:gateway'/>" +
							" </iq>";
			connection.sendXML(xml);
		}
		
		public function getServices():void
		{
			var xml:String = "<iq type='get' from='test@daniels-comp/xiff' to='daniels-comp' id='info1'>" +
							  " <query xmlns='http://jabber.org/protocol/disco#items'/></iq>";
			connection.sendXML(xml);
		}
		
		public function registerAIM():void
		{
			var token:AsyncToken = gatewayObject.call("Manager.addRegistration","flexisawesome",userInformation._JID,"aim",aim_username.text,aim_password.text,"");
			var tresponder:ItemResponder = new ItemResponder(this.showAIMResult,this.onFault);
			
			token.addResponder(tresponder);
		}
		
		public function showAIMResult(event:ResultEvent,token:AsyncToken = null):void
		{
			Alert.show("Successfully registered for AOL Instant Messanger!");
		}
		
		public function onFault(event:FaultEvent, token:AsyncToken = null):void
		{
			consoleMsg.text = consoleMsg.text + "\n\n\n\n" + event.fault.faultString + "\n\n" + event.fault.faultDetail;
			Alert.show(event.fault.faultString,event.fault.faultCode);
		}
		
		public function getAIM():void
		{
			var xml:String = "<iq type='get' from='test@daniels-comp/xiff' to='aim.daniels-comp' id='info1'>" +
							  " <query xmlns='http://jabber.org/protocol/disco#items'/></iq>";
			connection.sendXML(xml);
		}
		
		/**
		** Set User Presence
		**/
		
		public function setPresence():void
		{
			roster.setPresence(cbPresence.selectedItem.label,cbPresence.selectedItem.label,0);
			AIMPresence();
		}
		
		public function AIMPresence():void
		{
			roster.setPresence("away","Wooing Juliet",1);
			var xml:String = '<presence><show>away</show><status>Wooing Juliet</status></presence>';
		//	connection.sendXML(xml);
		}
		
		private function doLogin():void
		{
			connection.username = username.text;
			connection.password = password.text;
			userInformation._JID = username.text + "@daniels-comp";
			userInformation._username = username.text;
			userInformation._password = password.text;
			connection.connect("flash");
			currentState = '';
		}
		
		private function sendMessage():void
		{
			room.sendMessage(msg.text);
			msg.text == "";
		}
		
		private function handleConnectSuccess(event:ConnectionSuccessEvent):void
		{
			consoleMsg.text = consoleMsg.text + "Connected! \n\n\n\n";
			
		}
		
		private function handleRoomJoin(event:RoomEvent):void{
			room.sendMessage("test has joined the room");
		}
		
		private function handleServerLogin(event:LoginEvent):void{
			trace("Login event recieved");
			roster.setPresence(null, "Online", 5);
			room.join();
		}
		
		private function handleIncomingData(event:IncomingDataEvent):void
		{
			if(event.data.firstChild.nodeName == "iq")
			{
				if(event.data.firstChild.firstChild.attributes.xmlns == "jabber:iq:roster")
				{
					var tmpObj:Object = {};
					tmpObj.name = event.data.firstChild.firstChild.firstChild.attributes.name;
					tmpObj.group = event.data.firstChild.firstChild.firstChild.firstChild.nodeValue;
					tmpObj.jID = event.data.firstChild.firstChild.firstChild.attributes.jid;
					buddyListdp.addItem(tmpObj);					
				}
						
			}
			if(event.data.firstChild.nodeName == "message")
			{
				var tmpXML:XMLList = new XMLList(event.data);
				if(tmpXML.body == null)
				{
					//do nothing
				}else{
					var nickname:String = event.data.firstChild.attributes.from;
					var nickname_array:Array = nickname.split("/");
					nickname = nickname_array[1];
					var jid:String = event.data.firstChild.attributes.from;
					//if(chatWindows1.getChildByName(jid))
					//if(_chatWindow.chatJID == jid)
					//{
					//  Alert.show("score");//_chatWindow.display.text = _chatWindow.display.text + nickname + ": " + tmpXML.body + "\n\n";
					//}
					if(nickname == null)
					{
						var nick:String = event.data.firstChild.attributes.from;
						var nick2:Array = nick.split("\\40");
						nickname = nick2[0]; 
					}
					consoleMsg.text = consoleMsg.text + nickname + ": " + tmpXML.body + "\n\n\n\n";
				}
			}
			consoleMsg.text = consoleMsg.text + event.data + "\n\n\n\n";
			
		}
		
		private function handleOutgoingData(event:OutgoingDataEvent):void
		{
			consoleMsg.text = consoleMsg.text + ">>>Sent: " + event.data + "\n\n\n\n";
		}
		
	 
	]]>
</mx:Script>
	<mx:TextArea id="consoleMsg" right="483" left="10" top="10" bottom="40"/>
	<mx:TextInput right="109" bottom="10" left="10" id="msg"/>
	<mx:Button label="Say It" click="sendMessage()" right="10" bottom="10" width="91" id="button1"/>
	<mx:DataGrid id="chatCodes" right="10" top="10" dataProvider="{errorCodes}" width="465" height="140">
		<mx:columns>
			<mx:DataGridColumn headerText="Code" id="codeField" dataField="errorCode"/>
			<mx:DataGridColumn headerText="Condition" dataField="errorCondition"/>
			<mx:DataGridColumn headerText="Message" dataField="errorMessage"/>
			<mx:DataGridColumn headerText="Type" dataField="errorType" />
		</mx:columns>
	</mx:DataGrid>
	<mx:Label text="Presence:" id="label1" right="414" top="160"/>
	<mx:ComboBox id="cbPresence" top="158" right="246" width="160" dataProvider="{presenceCodes}" change="setPresence();"></mx:ComboBox>
	<mx:Button label="&lt;- Clear" click="consoleMsg.text = &quot;&quot;;" id="button2" right="403" top="186"/>
	<mx:Button label="Get Users" click="getUsers();" id="button5" right="394" top="216"/>
	<mx:Button label="Room Browser" id="button4" right="366" top="246" click="currentState = 'roomBrowser';"/>
	<mx:Button label="Register for AIM" click="currentState = 'registerAIM';" id="button3" right="354" top="276"/>
	<mx:Button label="Get Roster" right="308" top="186" click="getRoster();" id="button6"/>
	<mx:Button label="Private Messages" right="260" top="216" click="currentState = 'pm';" id="button7"/>
	<mx:Button label="Chat with somebody" click="currentState = 'startChat';" id="button8" right="217" top="246"/>
	<mx:DataGrid id="buddyList" dataProvider="{roster}" bottom="40" left="805" right="10" top="306">
		<mx:columns>
			<mx:DataGridColumn headerText="Name" dataField="displayName"/>
			<mx:DataGridColumn headerText="Group" dataField="group"/>
			<mx:DataGridColumn headerText="Status" dataField="status"/>
		</mx:columns>
	</mx:DataGrid>
	<mx:Button label="Chat Windows" top="276" right="240" click="currentState = 'chatWindows';" id="button9"/>
	<mx:Button label="Button" click="addTab('test',chatWindows1);" right="410" width="65" top="305" height="22" id="button10"/>
</mx:Application>