<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns2="*" creationComplete="init_fun()" focusIn="text_focus()">
<mx:Script>
 <![CDATA[
  import flash.net.Socket;
  import mx.controls.Alert;
  public var temp_socket:Socket=new Socket();
  public var temp_int:int=1;
  [Bindable] public var user_men_text:String;
  public function text_focus():void
  {
   if(viewstack1.selectedIndex==1)
    input_id_text.setFocus();
  }
  public function init_fun():void
  {
  var time:Date = new Date() ;

    var hours   : uint = time.getHours();
    if(hours<9 || hours>18)
    viewstack1.selectedIndex=2;
   
  }
  public function connect_fun():void
  {
   var temp_str:String;

   configureListeners(temp_socket);
   //temp_socket.connect(ip_text.text,Number(port_text.text));
   temp_socket.connect("118.131.10.26",20203);
  }
  private function configureListeners(dispatcher:IEventDispatcher):void
  {
         dispatcher.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
         dispatcher.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
         dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securiteHandler);
  }
  private function securiteHandler(even:SecurityErrorEvent):void
  {
   viewstack1.selectedIndex=2;
  }
  private function ioErrorHandler(event:IOErrorEvent):void
  {
   viewstack1.selectedIndex=2;
  }
  private function socketDataHandler(event:ProgressEvent):void  //데이터 받을때
  {
         var read:ByteArray;
         var temp_str:String;
   read=new ByteArray;
         temp_socket.readBytes(read , 0 , 0);
         temp_str=read.toString();
         if(temp_int)
   {
    temp_socket.writeUTFBytes("mem"+input_name.text);
    temp_socket.flush();
    viewstack1.selectedIndex=1;
    temp_int=0;
   }
         if(temp_str.length>0)
         {
          if(temp_str.substr(0,3)=='<fo')
          {
           text_area.htmlText+=temp_str.substr(0,temp_str.length);
           text_area.htmlText+='\n';
          
           if(snd_checked.selected)
           {
            var request2:URLRequest = new URLRequest("sound_play.mp3");  //사운드 재
            var snd:Sound = new Sound();
         var sndChannel:SoundChannel;
      snd.load (request2) ;
      sndChannel = snd.play() ;
           }
          }
          else if(temp_str.substr(0,3)=='mem')
          {
           user_men_text='';
           user_men_text=temp_str.substr(3,temp_str.length);
           //우측에 접속자수
          }
         }
       

  }
  private function chk_enter(event:KeyboardEvent):void
  {
   if(event.charCode==13)
    on_send();
  }
  public function on_send():void
  {
   var text_str:String=input_id_text.text;
   
   for(var i:int=0;i<100;i++)
    text_str=text_str.replace('<','');
     
   var temp_str:String="<font color='#"+sel_color.selectedColor.toString(16)+"'><b>"+input_name.text+" : "+text_str+"</b></font>"
   try{
    temp_socket.writeUTFBytes(temp_str);
    temp_socket.flush();
    input_id_text.text="";
   }
   catch(e:IOError){
    viewstack1.selectedIndex=2;
   }
  }
  public function exit_function():void
  {
    
  }
 ]]>
</mx:Script>
  <mx:Iris id="irisOut" duration="500" showTarget="true"/>
    <mx:Iris id="irisIn" duration="500" showTarget="false"/>
 <mx:ViewStack x="10" y="78" id="viewstack1" width="605" height="440">
  <mx:Canvas label="View 1" width="100%" height="100%" hideEffect="irisOut">
   <mx:Panel x="124" y="71" width="334" height="251" layout="absolute" title="어서오세용~" fontSize="12">
<!--    <mx:TextInput id="ip_text" x="121.5" y="36" text="118.131.10.26"/>
    <mx:TextInput id="port_text" x="121.5" y="68" displayAsPassword="true"/>-->
    <mx:TextInput id="input_name" x="121.5" y="100" width="160"/>
    <mx:Button x="102" y="145" label="접속하기" width="110" height="40" click="connect_fun()"/>
    <mx:Label x="32.5" y="40" text="접속 IP"/>
    <mx:Label x="32.5" y="72" text="비밀번호"/>
    <mx:Label x="32.5" y="104" text="사용할 대화명"/>
   </mx:Panel>
   <mx:Label x="124" y="330" text="안된다고 막누르지말고 접속하기" width="334" height="35" fontSize="20"/>
   <mx:Label x="124" y="363" text="한번 클릭하고 기다리세요" width="334" height="35" fontSize="20"/>
  </mx:Canvas>

  <mx:Canvas label="View 2" width="100%" height="100%" show="{input_id_text.setFocus()}" showEffect="irisIn" >
   <mx:Panel x="0" y="0" width="100%" height="100%" layout="absolute" title="채팅창" fontSize="12">
    <mx:TextArea id="text_area" x="10" y="10" width="431" height="347" editable="false" fontSize="12" valueCommit="text_area.verticalScrollPosition = text_area.maxVerticalScrollPosition;" cornerRadius="10"/>
    <mx:ColorPicker id="sel_color" x="449" y="367" width="24" height="21"/>
    <mx:TextArea id="member_area" x="449" y="10" width="126" height="290" cornerRadius="10" text="{user_men_text}"/>
    <ns2:fastTextInput id="input_id_text" width="431" height="23" cornerRadius="10" x="10" y="365" borderStyle="solid" keyDown="chk_enter(event)"/>
    <mx:Button x="449" y="308" label="내용지우기" width="126" click="text_area.text=''"/>
    <mx:Button x="449" y="335" label="연결종료" width="126" click='exit_function()' />
    <mx:CheckBox x="486" y="370" label="소리" width="76" id="snd_checked"/>
   </mx:Panel>
  </mx:Canvas>
    <mx:Canvas label="" width="100%" height="100%">
   <mx:Label x="49" y="59" text="서버 오픈시간이 아닙니다" width="483" height="46" fontSize="30"/>
   <mx:Label x="49" y="113" text="9~19시까지만 오픈합니다" width="483" height="46" fontSize="30"/>
   <mx:Label x="49" y="167" text="9~19시인데 이 메세지가 뜨면" width="483" height="46" fontSize="30"/>
   <mx:Label x="49" y="221" text="rezaros@nate.com 네이트 " width="483" height="46" fontSize="30"/>
   <mx:Label x="49" y="275" text="친등한담에 문의하세요" width="483" height="46" fontSize="30"/>
  </mx:Canvas>
 </mx:ViewStack>
</mx:Application>

'프로그래밍 언어 > FLASH, FLEX' 카테고리의 다른 글

textarea auto scroll  (0) 2008.05.06
Application.application  (0) 2008.05.06
datagrid itemrenderer 사용시 progressbar 문제  (0) 2008.04.15
DataGrid Data 입력  (0) 2008.04.11
parameter 처리  (0) 2008.04.11
블로그 이미지

용병

,