# Need help on netconnetion.connect

**URL:** <https://forum.kirupa.com/t/need-help-on-netconnetion-connect/322372>\
**Category:** Uncategorized\
**Created:** [May 19, 2011, 12:21pm UTC](https://forum.kirupa.com/t/need-help-on-netconnetion-connect/322372 "2011-05-19T12:21:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![solomonde2000](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@solomonde2000](https://forum.kirupa.com/u/solomonde2000)\
**Post date:** [May 19, 2011, 12:21pm UTC](https://forum.kirupa.com/t/need-help-on-netconnetion-connect/322372/1 "2011-05-19T12:21:30Z")

</div>

HI,  
i’m new to streaming media and i’m using red5 server,i try to play a flv,but it always showing netconnection.connet.rejected.please help me on this,whether i have to import server side code.

my code:AS3

import fl.controls.ComboBox;

var myNc:NetConnection = null  
var myNs:NetStream = null  
var myVideo:Video  
var myVideoObj:Object  
var strVideoName:String

var myComboBox  
init()

function init()  
{  
createComboBox()

}

function createComboBox()  
{  
myComboBox = new ComboBox()  
myComboBox.setSize(150, 22);  
myComboBox.prompt = “Select a destination”;  
myComboBox.addItem( { label: “Server”, data:“rtmp://localhost/AudioTest” } );  
myComboBox.addItem( { label: “Client”, data:null } );  
myComboBox.addEventListener(Event.CHANGE, selectedPath);  
addChild(myComboBox)  
}

function selectedPath(e:Event):void {  
trace(myComboBox.selectedItem.label);  
if(myVideo != null)  
{  
myNs.close()  
removeChild(myVideo)  
myNs = null  
myVideoObj = null  
myVideo = null  
}  
switch(myComboBox.selectedItem.label)  
{  
case “Server”:  
trace(“connection Failed”)  
strVideoName =“stream”  
break;  
case “Client”:  
strVideoName = “test.flv”  
break;  
default:

```
}
createConnection(myComboBox.selectedItem.data)

```

}

function createConnection(pValue)  
{  
myNc = new NetConnection()  
myNc.addEventListener(NetStatusEvent.NET\_STATUS, connectionStatusHandler)  
myNc.connect(pValue)

}

function connectionStatusHandler(evt)  
{  
switch(evt.info.code)  
{  
case “NetConnection.Connect.Failed”:  
trace(“connection Failed”)  
break;  
case “NetConnection.Connect.Rejected”:  
trace(“connection Failed”)  
break;  
case “NetConnection.Connect.Success”:  
createStream()  
break;

```
    default:
    
}

```

}

function createStream()  
{  
if(myNs == null)  
{  
myNs = new NetStream(myNc)  
myNs.addEventListener(NetStatusEvent.NET\_STATUS,streamStatusHandler)

```
}
buildVideo()

```

}

function streamStatusHandler(evt)  
{  
switch(evt.info.code)  
{  
case “NetStream.Play.Stop”:  
trace(“video stopped”)  
break;  
case “NetStream.Play.Start”:  
trace(“video started”)  
break;  
case “NetStream.Buffer.Full”:  
//trace(“video Buffer.Full”)  
break;

```
    default:
    
}

```

}

function buildVideo()  
{  
myVideoObj = new Object()  
myNs.client = myVideoObj  
myNs.play(strVideoName)  
myVideo = new Video()  
myVideo.x = 100  
myVideo.y = 100  
myVideo.attachNetStream(myNs)  
addChild(myVideo)  
}

:hr:
