A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: XMLSocket receive data help

Threaded View

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    4

    XMLSocket receive data help

    I am having newbie problems with sockets. Flash sends data to my php server script fine, and my telnet client(s) all get updated. When I make an entry into a telnet client, all of the other clients update immediately as expected. In Flash however, the only time I receive data is when I press a key within flash. Example:
    Press 'a' within Flash, flash traces a, telnet outputs a
    Press b in telnet, telnet outputs b, nothing within flash
    Press c in Flash, flash traces b, c, telnet traces c

    Here is my updated code:
    package {
    import flash.display.Sprite;
    import flash.net.*;
    import flash.events.*;
    import org.flashdevelop.utils.FlashConnect; //for trace

    public class Thisisatest2 extends Sprite
    {
    private var mySocket:XMLSocket;

    public function Thisisatest2()
    {
    mySocket = new XMLSocket();
    mySocket.addEventListener(Event.CONNECT, onConnect);
    mySocket.addEventListener(Event.CLOSE, onDisconnect);
    mySocket.addEventListener(DataEvent.DATA, onData);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, sendMsg);
    mySocket.connect("192.168.2.4", 8999);
    }

    private function onConnect(event:Event):void{
    FlashConnect.trace("<b>Server connection established!</b>");
    }

    private function onDisconnect(event:Event):void{
    FlashConnect.trace("<b>Server connection lost</b>");
    }

    private function onData(event:Event):void {
    FlashConnect.trace("data: " + event.data);
    }

    private function sendMsg(event:KeyboardEvent):void
    {
    mySocket.send(event.keyCode);
    }
    }
    }

    I guess this is more of an issue of how to set up Flash to listen for events on the socket
    Any ideas appreciated, thanks.
    Last edited by vamp4l; 07-02-2009 at 07:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center