Hi,
I’m trying to figure out a nice way to handle connecting with a client made in Flash CS3 to a Flash Media Server (3.5).
I intendedly called the connect method with some random IP and tried to control a scenario in which connecting to the server would fail - there seems to be however no timeout after which some Error would pop up or something… as I’m fairly new to AS3 I came up with an Idea I would like somebody experienced at AS3 to comment on :
I have a Connect button, to which I add a listener :
bConnect.addEventListener(MouseEvent.CLICK, fmsConnect);
The fmsConnect function invokes the connect method :
nc.connect(".........");
When the client connects to the server successfully, the NetStatusEvent changes, so to move to frame 2 I use another listener :
nc.addEventListener(NetStatusEvent.NET_STATUS, onStat);
So my onStat function actually controls the main timeline :
function onStat(nse:NetStatusEvent) {
if (nse.info.code == "NetConnection.Connect.Success") {
gotoAndStop(2);
} else {
//.....................
}
}
Now, since the NetConnection.Connect.Rejected won’t pop up in the dead end scenario, I decided I could add a timer to fmsConnect :
var timer:Timer = new Timer(15000, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timedCheckConnection);
timer.start();
and finally check if anything happened after those 15 seconds :
function timedCheckConnection(event):void {
if(!nc.connected) {
//................................
} else {
//................................
}
}
Is this too messy and is there some smarter way to do it ?