flex xmlsocketѧϰ
1¡¢XMLSocket¶ÔÏó¼ò½é
ÔÚ¸ÅÊöÀÒѾÌáµ½¹ýÁËFlashÀïµÄXMLSocket¶ÔÏó£¬ËüÊÇʵÏÖFalshºÍ·þÎñÆ÷Socket¼ä
ͨÐŵĺËÐÄ¡£ËüÔÊÐí°üº¬FlashÓ¦ÓõÄä¯ÀÀÆ÷Óë·þÎñ¶Ë½¨Á¢socketÁ¬½Ó£¬Ö®ºóFlashÓ¦ÓÃÓë·þÎñ¶Ë¾Í¿ÉÒÔÏ໥·¢ËÍXMLÊý¾Ý£¬¶øÇÒÔÚÒ»¸ö
socketÁ¬½Ó½¨Á¢Ö®ºó£¬ÔÚ¸ÃÁ¬½ÓÉÏ´«Ë͵ÄÊý¾ÝÁ¿ÊÇûÓÐÏÞÖƵģ¬Ö±µ½socketÁ¬½Ó¹Ø±Õ¡£XMLSocket¶ÔÏóÒ»¸ö×î´óµÄºÃ´¦ÊÇÒÔXML¸ñʽÀ´·â×°
ÄãµÄÊý¾Ý£¬ÕâÑùÔÚ·þÎñÆ÷¶Ë»òflashÀïÄã¿ÉÒÔºÜÇáËɵĴ¦Àí¸÷ÖÖ¸´ÔÓµÄÊý¾Ý¡£
XMLSocket¶ÔÏóÖ»ÓÐ3ÖÖ·½·¨ºÍ4ÖÖʼþ£º
£¨1£©.XMLSocketµÄ·½·¨£º
¢Ù. connect(·þÎñÆ÷µØÖ·£¬¶Ë¿ÚºÅ) £º³¢ÊÔÁª½ÓÔ¶³Ì¼ÆËã»ú
ʾÀý£º
if (!mySocket.connect(null, 2000))
{
myTextField.text = "Á¬½Óʧ°Ü£¡";
}
Æä
ÖУ¬connect·½·¨ÓÐÁ½¸ö²ÎÊý£¬µÚÒ»¸ö²ÎÊý±íʾҪÁ¬½ÓµÄÖ÷»ú£¬¿ÉÒÔÊÇÈ«ÏÞ¶¨µÄÓòÃûºÍÕßIPµØÖ·£¬ÐèҪעÒâÒ»µã£ºµ±Ê¹ÓÃIPµØַʱ£¬Èç
127.0.0.1
ÐèÒª°ÑËüµ±×÷×Ö·û´®À´´¦Àí£¬¼´ÒªÓÃÒýºÅ°ÑIPµØÖ·À¨ÆðÀ´¡£Èç¹ûΪnull£¬ÔòÁ¬½ÓWeb·þÎñÆ÷(´Ó¸ÃWeb·þÎñÆ÷ÏÂÔØÁË°üº¬µ±Ç°FlashÓ¦ÓõÄÍøÒ³)Ëù
ÔÚµÄIPµØÖ·¡£
µÚ¶þ¸ö²ÎÊý±íʾҪÁ¬½ÓµÄ¶Ë¿Ú£¬ÓÉÓÚµÍÓÚ1024µÄ¶Ë¿Ú±»Í¨ÓóÌÐòËùÕ¼£¬FlashµÄ°²È«¹æÔò²»ÔÊÐíÔÚµÍÓÚ1024µÄ¶Ë¿Ú½¨Á¢Á¬½Ó¡£connect·½·¨·µ»Ø²¼¶ûÐͱäÁ¿true»òfalse£¬±íʾÁ¬½ÓÊÇ·ñ³É¹¦¡£
ÒÔÉÏÓï¾äÖУ¬Èç¹ûÁ¬½Óʧ°Ü£¬connect·½·¨·µ»Øflase£¬Ôò°ÑmyTextField£¨ÎªÒ»·Ç¾²Ì¬ÎÄ×ÖTextField¶ÔÏóµÄʵÀý£©µÄÄÚÈÝÉèΪ“Á¬½Óʧ°Ü£¡”¡£
¢Ú. send(ÐÅÏ¢ÄÚÈÝ)£ºÔÚºÍÔ¶³Ì¼ÆËã»ú½¨Á¢Áª½Óºó£¬·¢ËÍÐÅÏ¢µ½Ô¶³Ì¼ÆËã»ú
ʾÀý£ºmySocket.send("<login username ='possible' password = '123' />");
ÆäÖУ¬²ÎÊý¿ÉÒÔÊÇÒ»¸öXML×Ö·û´®£¬Ò²¿ÉÒÔÊÇÒ»¸öxml¶ÔÏó£¬Èç¹ûÊÇxml¶ÔÏó£¬send·½·¨»áÏȽ«¶ÔÏóת»¯Îª×Ö·û´®£¬È»ºó½«¸Ã×Ö·û´®·¢Ë͵½·þÎñ¶Ë£¬²¢ÔÚ×Ö·û´®·¢Ëͺó£¬×·¼Ó·¢ËÍÒ»¸ö0×Ö½Ú¡£send·½·¨Ã»Óзµ»ØÖµ¡£
¢Û.close()£º¹Ø±ÕºÍÔ¶³Ì¼ÆËã»úÖ®¼äµÄÁª½á
ʾÀý£ºmySocket.close();
£¨2£©.XMLSocketµÄʼþ£º
¢Ù.onConnect(Áª»ú½á¹û)
µ±connect()Áª»ú·½·¨Ö´ÐÐÍê±Ïºó£¬Ëü»á´¥·¢²¢ÇÒ´«ÈëÒ»¸ö´ú±íÁª»úÊÇ·ñ³É¹¦µÄ²ÎÊý¸øonConnect()ʼþ£¬Èç¹ûÁª»ú³É¹¦£¬ÆäÖµ½«ÊÇtrue¡£
¢Ú.onData()
µ±XMLSocket½ÓÊÕµ½Ô¶³Ì¼ÆËã»ú´«ÈëµÄ×ÊÁÏʱ£¬¾Í»á´¥·¢onData()ʼþ¡£ËüºÍÏÂÃæ½²µÄonXML()ʼþ
µÄ²»Í¬Ö®´¦ÔÚÓÚ´ÓonData()ʼþÈ¡µÃµÄ×ÊÁÏÊÇÉÐδ¾¹ýflash½âÎöµÄÔʼ×Ö·û´®£¬¶ø´ÓonXML()ʼþÈ¡µÃµÄÊǾ¹ý½â
Ïà¹ØÎĵµ£º
public function submit():void{
//ÒªÇëÇóµÄURL
var request:URLRequest = new URLRequest("
http://localhost:8086/test.do
") ;
var load:URLLoader = new URLLoader() ;
//URL²ÎÊý
& ......
Ô´xmlÎļþ
<?xml version="1.0" encoding="iso-8859-1"?>
<books>
<stock>
<name>The Picasso Code</name>
<author>Dan Blue</author>
<category>Fiction</category>
<description>Cubist paintings reveal a secret society of people ......
¡¾±àÒë²ÎÊý¡¿
-default-background-color int
-default-frame-rate int
-default-size width height
ÉèÖÃSWFµÄ±³¾°É«£¬Ö¡ÆµÓë¿í¸ß£¬Õâ¸öÒ²¿ÉÒÔͨ¹ýÔª±êÇ©ÉèÖã¬ÖîÈç
[SWF(width="720",height="560",backgroundColor="#000000")]
-default-script-limits
-max-recursion-depth
-max-execution-time
¶¨ÒåÓ¦Óýű¾³ÌÐ ......
Ò»¡¢×Ô¶¨ÒåPanel×é¼þ
package test
{
import mx.containers.Panel;
import mx.core.UIComponent;
/**
* ×Ô¶¨ÒåPanel
* **/
public class MyPanel extends Panel
......