Share Pastebin
Guest
Public paste!

ths

By: a guest | Jul 14th, 2009 | Syntax: ActionScript | Size: 2.47 KB | Hits: 98 | Expires: Never
Copy text to clipboard
  1. package
  2. {
  3.  
  4.         import flash.display.Sprite;
  5.         import flash.events.*;
  6.     import flash.net.XMLSocket;
  7.        
  8.         import flash.display.Sprite;
  9.         import flash.text.TextField;
  10.         import flash.text.TextFieldAutoSize;
  11.         import flash.text.TextFormat;
  12.  
  13.         /**
  14.          * largement à poursuivre !
  15.          */
  16.  
  17.          
  18.          public class Main extends Sprite
  19.         {
  20.                 public var dataXML:XML;
  21.                
  22.                 public var room                         :       String                  =       new String( "salon-d-essai" )
  23.                 public var nickName             :       String                  =       new String( "ths" )
  24.                 public var contribution :       String                  =       new String("hello world")
  25.                
  26.                 public var nbrVisiteurRoom              :       int             =       new int( 0 )
  27.                 public var nbrVisiteurTotal             :       int             =       new int( 0 )
  28.                
  29.                 public var label:TextField;
  30.                 public var labelText:String;
  31.                
  32.                
  33.                 public function Main():void
  34.                 {      
  35.                
  36.                         // connection au socket XML
  37.                         var connexion           :       XMLSocket       =       new XMLSocket( )
  38.                         connexion.connect( "127.0.0.1" , 2468 ) // adresse - port
  39.                        
  40.                         // evenements
  41.                         connexion.addEventListener( Event.CONNECT , connexionSuccess )
  42.                         connexion.addEventListener( Event.CLOSE , connexionFermeture )
  43.                         connexion.addEventListener( DataEvent.DATA , receptionData )
  44.                                                
  45.                        
  46.                         //si la connexion reussi:
  47.                         function connexionSuccess (e:Event):void
  48.                         {                              
  49.                                 connexion.send( "<connect nickname='"+nickName+"' />" )
  50.                                 connexion.send( "<join room='"+room+"' />" )
  51.                                
  52.                                 // ** envoi à la ROOM uniquement
  53.                                 connexion.send("<msg toroom='"+room+"' back='1'><![CDATA["+contribution+"!>]]></msg>")
  54.                                
  55.                                 // ** envoi à tout le monde----------------------------------------------------------------   marche pas ?
  56.                                 //connexion.send("<msg broadcast='1' back='1'>HELLO WORLD !</msg>")
  57.                                
  58.                                 // ** deconnexion
  59.                                 //connexion.send("<m r='"+room+"' back='1' >salut !</m>")
  60.                                 //connexion.send("<quit r='XXX' />")
  61.                                
  62.                                 // ** getInfos ----------------------------------------------------------------------------   marche pas ?
  63.                                 //connexion.send("<getinfo />")
  64.                         }
  65.                                                
  66.                         //quand des données arrivent
  67.                         function receptionData (e:DataEvent):void
  68.                         {
  69.                                 dataXML =       new XML(e.data)
  70.                                 if ( dataXML.name()     == "m" )                trace ( "message: "     + dataXML )    
  71.                                 if ( dataXML.name()     == "room" )     trace ( "salon: "               + dataXML.@name )
  72.                                 if ( dataXML.name()     == "room" )             trace ( "nbrRoom: "     + dataXML.@clients )
  73.                                 if ( dataXML.name()     == "clients")   trace ( "nbrRoom: "     + dataXML.@nb )        
  74.                         }
  75.        
  76.                         function connexionFermeture ( e:Event ):void
  77.                         {
  78.                                 trace(" *** connexion fermeture ***")
  79.                         }
  80.                
  81.                 }
  82.                
  83. }      
  84.        
  85. }