我需要从服务器连续接收数据到闪存客户端,并且可以在 as3 中使用以下代码:
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");
}
}
不幸的是,我用 as2 编写的项目,是否可以在 flash as2 中完成这项工作?