Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Curly Braces without a Starting "Declaration"?

Explorer ,
Jun 19, 2013 Jun 19, 2013

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

TOPICS
ActionScript
763
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 19, 2013 Jun 19, 2013

those brackets don't do anything.  the code is the same as if they were absent.

however, if there was a config constant that prerecorded the brackets, the brackets would enclose code that is conditionally compiled.  ie, compiled depending on the condition (true or false) of the config constant.

specifically,

CONFIG::WEB{

    if (connectedSocket == 2) {

        chatConnect();

    }

}

would compile if CONFIG::WEB is true (in the config constants panel, file>publish settings>advance actionscript 3 setting

...
Translate
Community Expert ,
Jun 19, 2013 Jun 19, 2013

those brackets don't do anything.  the code is the same as if they were absent.

however, if there was a config constant that prerecorded the brackets, the brackets would enclose code that is conditionally compiled.  ie, compiled depending on the condition (true or false) of the config constant.

specifically,

CONFIG::WEB{

    if (connectedSocket == 2) {

        chatConnect();

    }

}

would compile if CONFIG::WEB is true (in the config constants panel, file>publish settings>advance actionscript 3 settings - wrench icon>config constants).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2013 Jun 19, 2013

Hey kglad, ok cool that makes sense then... Thanks for the explaination!

So I guess in the case where there is no conditional expression before the curly braces, the only real purpose it would serve is

merely cosmetic/readability or I guess it could help the programmer organize his or her code...

Again, thanks for the explaination!

Thanks Again,

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2013 Jun 19, 2013

exactly.

but, more likely, the author was using conditional compiling but did a find/replace and posted the edited code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2013 Jun 19, 2013
LATEST

Oh ok, I gotcha...

Thanks Again,

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines