Tutorial – AS3 XML Sockets
by Carlos Pinho, June 5th, 2007
  • Share
  • Share

Hello m8′s,

Here is a new tutorial about AS3.

Quote

AS3 XML Sockets

I started to research the script library for as3 on flash 9 and figured out how to do xml its alot harder this time around :( sorry to say but I got all the functions onConnect(TRUE OR FALSE) and onDisconnect() and yes they do work :)

Alright after 30 mins of testing I got it working and got all the listeners and event handlers ready to go for you all first Listeners and initiate :)

var xml_s=new XMLSocket(); xml_s.connect(ip,port);xml_s.addEventListener(Event.CONNECT,xmlsocket);//OnConnect// xml_s.addEventListener(Event.CLOSE,xm lsocket);//OnDisconnect//xml_s.addEventListener(IOErrorEvent.I O_ERROR,xmlsocket);//Unable To Connect//

Now for listener handlers :)

public function xmlsocket(Event):void{ switch(Event.type){case 'ioError': //Unable to Connect :( //break; case 'connect'://Connected :) // break;case 'close': //OnDisconnect :( //break; }}

Now to Send all you do is this.

xml_s.send("MESSAGE HERE");

This tutorial was published in http://www.actionscript.org

Brgds,

CP

Copy and Paste the code below
Email and IM
Websites
Forums
Get This

No Responses to “Tutorial – AS3 XML Sockets”

  1. palani Says:

    I want a resource files

  2. Yosef FLomin Says:

    you have some extra spaces in that code that gives errors.
    Heres the fixed code:

    var xml_s=new XMLSocket();

    xml_s.connect(‘yosefflomin’,8080);

    xml_s.addEventListener(Event.CONNECT,xmlsocket);//OnConnect//

    xml_s.addEventListener(Event.CLOSE,xmlsocket);//OnDisconnect//

    xml_s.addEventListener(IOErrorEvent.IO_ERROR,xmlsocket);//Unable To Connect/

    function xmlsocket(Event):void{

    switch(Event.type){
    case ‘ioError’: //Unable to Connect :( //
    trace(‘Couldnt Connect’);
    break;

    case ‘connect’: //Connected :) //
    trace(‘Connected!’);
    break;

    case ‘close’: //OnDisconnect :( //
    trace(‘Disconnected!’);
    break; } }

    xml_s.send(“MESSAGE HERE”);

  3. Yosef FLomin Says:

    oH, and you need to replace the quotation marks as this form converts them into symbols rather than quotes that flash understands

  4. Carlos Pinho Says:

    tnx m8

  5. Santiago Andrade Says:

    I see you can send data, but i cant receive data, how can i do that?

  6. Biga Says:

    I’m not used to AS3 but I guess the principle is the same, you should set an eventListener with the event Event.ONDATA or ONXML (I guess, I don’t have AS3 doc here), and then catch the string (or XML-node)

  7. Schafkopf Says:

    It’s actually
    xmlSocket.addEventListener(DataEvent.DATA, onData);
    But the XML data has to be decoded manually (misleading class name!):
    var xml = new XML(DataEvent.data);

Let leave a Comments for this post.