Is there a method like URLStream in as2?

137 Views Asked by At

i need to receive data continuously from server to flash client and it is possible in as3 with this code :

    public class ASHXTest extends Sprite
    {
        public function ASHXTest()
        {
            this.init();
        }

        private var urlStream:URLStream;
        private var outField:TextField;

        private function init():void
        {

            var req:URLRequest = new URLRequest("http://5.9.121.41/Handler.ashx");
            urlStream = new URLStream  ;
            urlStream.addEventListener(ProgressEvent.PROGRESS,onStreamProgress);
            urlStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
            urlStream.addEventListener(IOErrorEvent.IO_ERROR,onError);
            urlStream.load(req);

            outField = new TextField  ;
            outField.autoSize = "left";
            this.addChild(outField);
        }
        protected function onError(event:Event):void
        {
            outField.text = event.toString();
        }
        protected function onStreamProgress(event:ProgressEvent):void
        {
            var data:String = urlStream.readUTFBytes(urlStream.bytesAvailable);
            outField.appendText(data + "\n");
        }
    }

Unfortunately my project written in as2 , is it possible in flash as2 to do this job?

1

There are 1 best solutions below

3
On

It's been a little while since I have used this, but I think XMLSocket may be what you want? It doesn't actually need to use xml I don't think, but can be just a socket.

Link to documentation: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000442.html