Skip to main content
calmchessplayer
Inspiring
May 23, 2010
Question

disconnecting on fly

  • May 23, 2010
  • 2 replies
  • 959 views

I'm disconnecting and reconnecting my app in the following way ..my problem is when i disconnect and then reconnect the client is disconnected an undesireable time however this behavior is intermittant and sometimes the application behaves as exspected and stays connected can you see where my problem is? or maybe you know a better way to construct this disconnect/reconnect function.I'm useing AS3

reconnect =0;//default value changes to 1 or 2 when function is called

reconnectIt(reconnect);


public function reconnectIt(reconnect =null):void{

if(reconnect ==2){
nc1.removeEventListener(NetStatusEvent.NETSTATUS,connecthandler);
nc1.close();
nc1.makeconnection("rtmp://domain/test/instance0");
nc1.addEventListener(NetStatusEvent.NETSTATUS,connecthandler);
}else if (reconnect==1){
nc1.removeEventListener(NetStatusEvent.NETSTATUS,connecthandler);
nc1.close();
nc1.makeconnection("rtmp://domain/test/instance1");
nc1.addEventListener(NetStatusEvent.NETSTATUS,connecthandler);
}else if (reconnect ==0){
nc1.makeconnection("rtmp://domain/test/instance0");
nc1.addEventListener(NetStatusEvent.NETSTATUS,connecthandler);
}

}

    This topic has been closed for replies.

    2 replies

    Adobe Employee
    May 24, 2010

    Hi

    I got your problem but I need to know how you are modifying reconnect variable when reconnectlt method is invoked and also how your reconnectlt method is getting invoked first time. Can you be more descriptive on these things this will help me to understand the flow of your code?

    Regards,

    Amit

    calmchessplayer
    Inspiring
    May 24, 2010

    simply i call the  function on button press that says calll reconnect function and send variable somthing like

    rconBtn.addEventListener (MouseEvent.CLICK,SendReCon,false,0,true);

    private function SendReCon(MouseEvent):void{

    reconnect = 1;

    main.ReConnect(reconnect);

    }

    the code is a bit more elaborate than this but this is the basic idea all my code lives in seperate class packages as i write object oriented AS3 ......hundreds of lines of code so i can't put it here. hopefully you can ask enough questions that i can just write the bits and pieces that you need

    Known Participant
    May 24, 2010

    I hope you know of the fact that Flash Player API throws an exception if you try to use NetConnection.connect function from a "netStatus" event handler. I don't know why exactly, but I know it's documented. It may have to do with internal API structure, protection against stack overflow etc

    Other than that, I have implemented behavior you are trying to achieve with no problems. Your function body looks simple, if a bit redundant. Instead of doing an if/switch on 'reconnect' value, just suffix it to the connection endpoint URI. Less code is less chance of error, that's a fact.

    Known Participant
    May 24, 2010

    I would like to help, but am having a hard time deciphering your post. Try punctuation :-)