You cant do all that in one single function and your stuff is out of order.
public function onCreationComplete(event:FlexEvent) : void {
// setup connection code
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS,
onConnectionNetStatus);
connection.client = this;
connection.connect("rtmp:/Red5Trhread");
}
public function onConnectionNetStatus(nse:NetStatusEvent){
if(nse.info.code=="NetConnectionConnectSuccess")
{ shared = SharedObject.getRemote("thread", connection.uri, false);
shared.client = this;
shared.addEventListener(SyncEvent.SYNC, receiveVariable);
shared.connect(connection);