Curly Braces without a Starting "Declaration"?
Hello All,
This may be a simple/stupid question but I couldn't find any information on it after Googling for an hour...
I was trying to figure out how I could get my XMLSocket in my program to try to reconnect if it fails, when I came across this page here:
http://www.as3codes.com/wiki/index.php?title=Socket_%26_PHP_Data_Tutorial
There is one section in that code, in the link above, which has a pair of curly braces wrapped around an if statement, followed by a seimcolon. I couldn't
figure out what the purpose of doing that was and what will it do..??
Here is that snippet of code I mentioned, the part I'm talking about is the BOLDED section:
*I included the snippets of code that are directly before and direclty after the section I'm talking about, this way you can sort of see it in context...
// IF SOCKET CLOSES...
chatSocket.onClose = function()
{
gotoAndStop("retry");
msg = "<br>"+discoMsg;
backupMsg = msg;
retryConnection();// WAIT 10 seconds before calling it to reconnect...
};
//Prevents this script from running on close retry.
{
if (connectedSocket == 2) {
chatConnect();
}
// START THE SHOW
};
/*==================================================================================== */
/* Socket Connection Timer */
/*------------------------------------------------------------------------------------ */
this.onEnterFrame = function() {
if (connectedSocket == retry) {
connecttimer += 1;
if (connecttimer == 30) {
connectsec = "Retrying in: 9 seconds.";
}
if (connecttimer == 60) {
connectsec = "Retrying in: 8 seconds.";
}
if (connecttimer == 90) {
connectsec = "Retrying in: 7 seconds.";
}
if (connecttimer == 120) {
connectsec = "Retrying in: 6 seconds.";
}
if (connecttimer == 150) {
connectsec = "Retrying in: 5 seconds.";
}
if (connecttimer == 180) {
connectsec = "Retrying in: 4 seconds.";
}
if (connecttimer == 210) {
connectsec = "Retrying in: 3 seconds.";
}
if (connecttimer == 240) {
connectsec = "Retrying in: 2 seconds.";
}
if (connecttimer == 270) {
connectsec = "Retrying in: 1 seconds.";
}
if (connecttimer>=300) {
msg = backupMsg;
chatConnect();// re-run the Socket Connection code...
connectsec = "Retrying NOW";
connecttimer = 1;
}
}
};
It seems that the person who wrote this actually uses the " { ... }; " quite often in his code (*i.e. curl braces followed by a semicolon). I'm thinking in
some of the places where they use that (*i.e. Like this ---> " .... = function() { ..... };" ) but also include "= function()". Is that just another way you
can write/declare a function in thoses cases where they use the code "... = function() {....};" ?
I also thought that maybe it was just another way to create EventListeners without explictly defining them before hand...? Kinda confused...
I know it's written in Actionscript 2, so maybe the question is moot since that style might be gone along with AS2?
Any thoughts would be greatly appreciated.
Thanks in Advance,
Matt
