Newer
Older
ubChattin / src / ubChattin.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp();" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="570" height="595" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#959595, #CFC5C5]">
  <mx:Script>
  <![CDATA[
    import mx.collections.ArrayCollection;
    
  	[Bindable]
    public var tvMaster:Master = new Master();
    [Bindable]
    private var uM:ContextMenu;
    private var chatHist:Array;
    private var chatHistPos:Number = 0;
    
    /* Entry Point To TUve */
    private function initApp():void {
      tvMaster.init(this);
            
      this.addEventListener(TextEvent.LINK,doOpenInfo);
      
      /* Get Global Variables */
      tvMaster.chanSpec = Application.application.parameters.channel;
      
      /* Fetch Register Channel Lust */
      tvMaster.tuveGetChans();
      
      /* Assemble Our Custom Context Menu */
      uM = new ContextMenu();
      uM.hideBuiltInItems();
      var cmi:ContextMenuItem = new ContextMenuItem("Whois",false);
      cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,doWhois);
      uM.customItems.push(cmi);
      cmi = new ContextMenuItem("Kick",false);
      cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,doKick);
      uM.customItems.push(cmi);
      
      chatHist = new Array();
      
      if (tvMaster.tvSO.data.volume != null)
        volume.value = Number(tvMaster.tvSO.data.volume);
      }
      
    private function doOpenInfo(event:TextEvent):void {
      tvMaster.tuveShowIW(Number(event.text));
      }
      
    public function doWhois(event:ContextMenuEvent):void {
      tvMaster.tvNetwork.sendData("WHOIS " + userDispList.selectedItem.@data + "\n");
      }
      
    public function doKick(event:ContextMenuEvent):void {
      tvMaster.tvNetwork.sendData("KICK " + tvMaster.currentChannel + ":" + userDispList.selectedItem.@data + ":Bye!\n");
      }
      
    
    private function sendText():void {
      var tmpString:String;
      if ((chatText.text.length > 0) && (tvMaster.tvNetwork.tvNetCon == true)) {
        var myPattern:RegExp = /</g;
        tmpString = chatText.text.replace(myPattern,"&lt;");
        
        if (chatText.text.length > 0) {
      	  chatHist.push(chatText.text);
      	  if (chatHist.length > 20)
      	    chatHist.shift();
            
      	  chatHistPos = chatHist.length - 1;
      	  }
        
      	if (chatText.text.indexOf("/") == 0) {
      	  tvMaster.parseCommand(tmpString);
      	  chatText.text = "";
      	  }
      	else {
          tvMaster.tvNetwork.sendData("MSG " + tvMaster.currentChannel + ":" + tmpString + "\n");
          var date:Date = new Date;
  	      chatWindow.htmlText += ("[" + tvMaster.fmtdDate() + "] " + tvMaster.userName + ": " + tmpString + "\n");
  	      chatText.text = "";
  	      }
  	    }
      } /* End sendText() */
      
   private function userClick():void {
   	 tvMaster.tvNetwork.sendData('WHOIS ' + userDispList.selectedItem.@data + '\n');
   	 tvMaster.findIM(userDispList.selectedItem.@data);
     }
      
    private function doHist(event:KeyboardEvent):void {
      if (event.keyCode == Keyboard.DOWN) {
      	if (chatHistPos != (chatHist.length - 1)) {
      	  chatText.text = chatHist[chatHistPos++];
      	  chatText.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN,true,false,0.0,103));
      	  }
      	else
      	  chatText.text = "";
        }
      else if (event.keyCode == Keyboard.UP) {
      	if (chatHistPos >= 0) {
      	  chatText.text = chatHist[chatHistPos--];
      	  chatText.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN,true,false,0.0,103));
      	  }
      	if (chatHistPos < 0)
      	  chatHistPos = 0;
        }
      }
      
    private function changeChan():void {
      tvMaster.tvNetwork.sendData("PART " + tvMaster.currentChannel + "\n");
      tvMaster.currentChannel = tvMaster.chanList[selChan.selectedIndex].channel;
      tvMaster.tvNetwork.sendData("JOIN " + tvMaster.currentChannel + "\n");
      tvMaster.userList = null;
  	  tvMaster.userList = new XMLList();
      }

    public function updateVolume():void	{
	  var st:SoundTransform = tvMaster.tvSyncNS.soundTransform;
	  st.volume = (volume.value) * .01;
	  tvMaster.tvSyncNS.soundTransform = st;
	  tvMaster.tvSO.data.volume = volume.value;
      } /* End updateVolume */
            
  ]]>
  </mx:Script>
 
  
  <mx:TextArea x="0" width="490" height="500" y="25" mouseUp="tvMaster.setClip(chatWindow)" click="focusManager.setFocus(chatText)" updateComplete="chatWindow.verticalScrollPosition = chatWindow.maxVerticalScrollPosition" editable="false" id="chatWindow" horizontalScrollPolicy="off" borderThickness="1"/>
  <mx:List id="userDispList" itemRollOver="userDispList.selectedIndex = event.rowIndex;" contextMenu="{uM}" height="500" width="77" dataProvider="{tvMaster.userList}" labelField="@label" doubleClickEnabled="true" doubleClick="userClick()" y="25" x="493"/>  	
  <mx:TextInput keyDown="doHist(event)" enter="sendText()" x="0" width="490" y="527" id="chatText" focusAlpha="0"  height="22"/>
  <mx:ComboBox width="120" dataProvider="{tvMaster.chanList}" id="selChan" labelField="channel" change="changeChan()"  paddingLeft="0" paddingRight="0" cornerRadius="0" y="0" x="0"/>
  <mx:Label x="493" y="528" id="myNick" text="{tvMaster.userName}" width="77" fontFamily="Georgia" fontSize="10" fontWeight="bold" />
  <mx:Label textAlign="left" x="0" y="550" id="songTitle" width="100%" />
  <mx:HSlider liveDragging="true" width="220" x="0" y="573" id="volume" snapInterval="1" value="75" maximum="100" change="updateVolume()"  height="22"/>
  <mx:Label x="120" y="0" height="22" id="topic" width="450" color="#000000" fontFamily="Georgia" fontSize="11" />
</mx:Application>