AS3 code question ?

Hello!

My first post!

Firs, I just want to say a big thankyou to Erin and ofcourse to Boris for their great amount of time put in developing and porting this great library.
So.. 🙂 THANKYOU guys, awesome work!

Now the question:
In my TestCompund.as file I read this in the constructor function:

Code:
public function TestCompound(){
         
         // Set Text field
         Main.m_aboutText.text = "Compound Shapes";
         
         var bd:b2BodyDef;
         var body:b2Body;
         var i:int;
         var x:Number;
         
         {
            var cd1:b2CircleShape = new b2CircleShape();
            cd1.SetRadius(15.0/m_physScale);
            cd1.SetLocalPosition(new b2Vec2( -15.0 / m_physScale, 15.0 / m_physScale));
            
            var cd2:b2CircleShape = new b2CircleShape();
            cd2.SetRadius(15.0/m_physScale);
            cd2.SetLocalPosition(new b2Vec2(15.0 / m_physScale, 15.0 / m_physScale));
            
            bd = new b2BodyDef();
            bd.type = b2Body.b2_dynamicBody;
            
            for (i = 0; i < 5; ++i)
            {
               x = 320.0 + b2Math.RandomRange(-3.0, 3.0);
               bd.position.Set((x + 150.0)/m_physScale, (31.5 + 75.0 * -i + 300.0)/m_physScale);
               bd.angle = b2Math.RandomRange(-Math.PI, Math.PI);
               body = m_world.CreateBody(bd);
               body.CreateFixture2(cd1, 2.0);
               body.CreateFixture2(cd2, 0.0);
            }
         }
// some other code here...

}


Here is my newbie questions:

1. whats up with the braket just before
Code:
var cd1:b2CircleShape = new b2CircleShape();
?

There seems not to be a function definition, or anything known to my eye... 🙂

2. This type of notation can be made only in the constructor or anywhere in the class?
3. Is there a functional scope or just to group some code chunks?

Again thankyou for your great work and hope to get the depths of this great library 🙂

GF.
It's just there to group the code. I liked to use them but FlashDevelop doesn't understand them and thus disables code hinting within the brackets.. So no more grouping for me.

You can just leave them away, it won't have effect on your code.


edit
btw to answer your other questions:

2 - you can test that yourself.. it's usable anywhere.

3 - flash has a pretty messed up 'scope'. In java, anything declared within the brackets is only available there, so it's a new scope. in Flash, all variables that may get declared in a function are declared at the start of that function, and available too (sucks when debugging). They are all set to 'undefined' I believe.
Ok, got it now 🙂 Tnx a bunch!..

GF.
I think its actually simpler than that... it looks like residual braces left over from the code being updated or ported. It 'could' be braces to define a block of code but since its not used anywhere else in the codebase I doubt it.

As a side note, you can do code folding in FlashDevelop. Use a comment block like this

Code:
//{ This marks the start of the region and will act as a title when folded
    Your code goes here...
//} this marks the end of the region and any text here will not show up when folded.


I use it quite often and you can nest them as well.
@ VengantMjolnir:

Hmmm.. I'm on Mac with FDT plugin under Eclipse and it does not work... May be a FlashDevelop specific feature?

Tnx,
GF
yes, its a FlashDevelop specific feature but most IDE's should offer region highlighting and folding. I'm not familiar with FlexBuilder though so YMMV
They are just grouping hints. My version of FlashDevelop folds on them, with or without comments. But the convention seems to be without comments.
@VengantMjolnir:

I'm on FDT, not Flex (http://www.fdt.powerflasher.com/developer-tools/fdt-3/home/)
I personally love the FDT enviroment, since there is no FlashDevelop on Mac or any other IDE for coding...

Cheers,
GF

Original thread: https://box2d.org/forum/viewtopic.php?t=4435