I'm new to ActionScript and have some problem with getting bytes from URLStream.
I'm trying to connect to a URL, and get the bytes from this URL.
I created private var urs:URLStream;
and urs.connected
returns true. Now I want to get the byte from this url. My code is:
public class myClass extends MovieClip
{
private var urs:URLStream;
private var ns:NetStream;
private var urr:URLRequest;
private var textStr:TextField;
public function myClass()
{
var urr:URLRequest;
var urs:URLStream;
urr=new URLRequest("http://myserver/video/video.flv");
urs=new URLStream();
urs.addEventListener(flash.events.ProgressEvent.PROGRESS,progresHnd);
urs.addEventListener(flash.events.Event.COMPLETE,completeHnd);
urs.addEventListener(flash.events.Event.CLOSE,closeHnd);
urs.addEventListener(flash.events.Event.OPEN,openHnd);
urs.load(urr);
if (urs.connected)
{
var myint:int = urs.readByte();
textStr.text = "success";
addChild(textStr);
}
else
{
textStr.text = "urs not connected";
addChild(textStr);
}
}
}
The code failed at urs.readByte();
. (Maybe with error #2030, not sure about it)
Someone can help me with a solution for this? (or give another way to get the bytes)
Thanks!
Connected means whether the server is connected or not, it does not mean that data loading is complete. To read bytes you need to wait until the data load is complete, i.e. you can read bytes in your complete handler.
Additional note, when you are adding
var urs:URLStream;
andvar urs:URLStream;
in constructor they are hiding class memberurs
andurs
. So you need to remove these declarations from constructor.