General Flash Questions

I'm looking at the Hello World fla. I can see that the three visuals in the library are linked to physics classes. I can also see that the blocks are instantiated in the HelloWorld.as class. My dumb question is:

Where is the initialization of the HelloWorld class occuring in the HelloWorld.fla?

Thanks
Hi canstein,
Not a dumb question at all.

The 'Document class' in HelloWorld.fla is set to 'HelloWorld', so the HelloWorld class in HelloWorld.as is used as the main class for the document, so when the application is run the 'Document class's constructor (HelloWorld() function) is called.

Hopefully that makes sense, and answers your question (there are way too many HelloWorld's in that sentence :P).
I found it! and that makes total sense. I started making the transition to actionscript 3.0 this past weekend (assuming that's a new as3 feature and I'm not talking out of my ass 🙂) and I had yet to use this option.

Thanks for the help and great work on this port. I'm so excited to play with it.
As long as this thread is already up, I have something that actually probably does qualify as a dumb question.

I've been playing around with AS3 lately (doing a simple port of a Java game for now), and I'm totally and utterly confused by some scoping issues. Maybe someone can enlighten?

Suppose I'm doing a few loops. The following code will have trouble:

Code: Select all

for (var i:int = 0; i<upper; ++i){
  //code here
}
//other stuff here
for (var i:int = 0; i<upper2; ++i){
  //code here
}


AS3 seems to still consider i to be in scope for the second loop - I realize that the solution is either to just re-use i (leave off the second declaration) or use a different variable for the counter, but I'm confused by the error. Clearly AS3 has some bizarre scoping rules, can anyone enlighten me as to what the deal is? [In particular, are there any other things that are weird that I should watch out for as compared to other Algol-style languages?]
variables declared inside loops don't have a separate scope from the function scope. AS3 shouldn't be throwing any compile errors on your code though, just "Warnings"

I usually declare my looping integers outside my for loops
Yes ninjascience is correct, and in addition there is no block-level scope at all in AS3.

Feel free to ask if you run into any other weird AS3 behavior, or just wonder how something in AS3 works as opposed to other languages like C. I've been using it nonstop for the last 4 months and I think I have used most of the basic language elements. Also, http://www.senocular.com/flash/tutorials/as3withflashcs3/ has been a really good reference for general AS3 stuff. Although it is aimed at Flash CS3, and I'm actually using Flex Builder 2. I haven't used the Flex framework stuff though because I'm doing games, so don't ask me about Flex components 😉
Ah, thank you, that makes sense (apart from the motivation - I can't see how from a language design point of view getting rid of block scope would be preferable, as block scoping allows loop optimizations that should be more difficult if inner variables stay "live" outside the block, but I assume the have their reasons; besides, what do I know, anyways, I'm not a JIT designer!). And yes, you're right, it was just a warning, but I'm shooting for zero-warning compiles as a general rule, at least until I know the language well enough to know when not to be concerned.

Another issue that bit me was that AS3 does not appear to allow constructor overloading, another choice that I can't for the life of me understand, but luckily (like the above issue) it's not too difficult to work around, esp. since they do allow default values to be passed. More just an issue when trying to port code from other languages...

In any case, thanks for the explanation!
Also, all variable declarations are moved to the top of the scope, so this will compile fine and print 100.

Code: Select all

i = 100;
var i:int;
trace(i);

Lots of little annoyances like no method/constructor/operator overloading, but nothing that's really too much trouble to work around as you said.

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