# \[AS3\] using the flash.net.NetConnection class

**URL:** https://forum.kirupa.com/t/as3-using-the-flash-net-netconnection-class/286333
**Category:** flash
**Created:** [April 14, 2009, 12:30am UTC](https://forum.kirupa.com/t/as3-using-the-flash-net-netconnection-class/286333 "2009-04-14T00:30:15Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Undre](https://avatars.discourse-cdn.com/v4/letter/u/7cd45c/32.png) [@Undre](https://forum.kirupa.com/u/Undre)
#### Post date: [April 14, 2009, 12:30am UTC](https://forum.kirupa.com/t/as3-using-the-flash-net-netconnection-class/286333/1 "2009-04-14T00:30:15Z")

</div>

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 :

```auto
bConnect.addEventListener(MouseEvent.CLICK, fmsConnect);

```

The fmsConnect function invokes the connect method :

```auto
nc.connect(".........");

```

When the client connects to the server successfully, the NetStatusEvent changes, so to move to frame 2 I use another listener :

```auto
nc.addEventListener(NetStatusEvent.NET_STATUS, onStat);

```

So my onStat function actually controls the main timeline :

```auto
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 :

```auto
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 :

```auto
function timedCheckConnection(event):void {
            if(!nc.connected) {
                //................................
            } else {
                //................................
            }
        }

```

Is this too messy and is there some smarter way to do it ?
