I keep meaning to post a link to this site... really great articles over there.... I highly recommend reading through them...
After reading Everything's a Function. I remembered another strange thing that I noticed about the ActionScript compiler and auto-formatting.
Auto-formatting in flash is totally broken and can completely ruin your code - so never use it. It's officially unusable as far as I'm concerned. I can dig up some code later and add it here... most people reading this probably know exactly what I'm talking about...
Anyway... one thing I've seen auto-formatting do is to remove the () after a class instantiation...
From this:
var s:Sprite = new Sprite();
to this:
var s:Sprite = new Sprite;
... and you would think the second one would break, but it doesn't - it works just fine.... very odd... to see it in action try this:
-
var s:Sprite = new Sprite;
-
with(s.graphics) beginFill(0xFF0000), drawCircle(0,0,500);
-
addChild(s);
Can anyone shed light on that?
10 Comments
Hey Zevan
Actually there isn’t much to say. ActionScript allows both formats if no arguments are passed to the constructor.
Yeah, it’s an old and expected behavior. I dunno if I remember correctly but in AS2 or AS3 the semicolon could be removed as well. There has been no flash documentation, I’ve come across that explains that behavior though.
Maybe I’m just being difficult, but I don’t like the fact that it works without () and I don’t like the fact the the auto-format button seemingly randomly removes the ().
I don’t mind the semicolon thing really…. I sometimes forget to put them here and there when I write code quickly…
Oh and I just remembered. Keith Peters may be the person, you could get a lot of help from about subject like these. He’s the man for flash and actionscript.
Thanks for the link and the kind words about my site.
As for the contructor syntax, it’s like everyone’s saying: both the parentheses and the semi-colon are optional. Well, the semi-colon is not optional if you try something like this:
There you really do need the semicolon to separate the two statements.
Thanks again for the kind words and congrats on a site full of great articles.
If I remember it right it’s the same in C++ but I think the code is less understandable if you write it without parentheses.
@Jackson Dunstan
>>Thanks for the link and the kind words about my site.
No problem - I had a real good time going through and reading most of the articles on your site. Figured I should send some more people there. I noticed that lots of people are also tweeting about your site. May have been how I came across it…
@DieTapete - You may be right - I’ll double check a little later (have a C++ proj I’m working on).
Imagine something like this:
var myNumber:Number=(a.rotation-_b)/2;
after autoformat:
var myNumber:Number=a.rotation-_b/2;
Auto-format is really good feature, believe me. ;]
is it because function names are read like vars? so:
” function MyFunction ” is the same as ” var MyFunction = new function; ”
I think this was what Mike N. was alluding too, or not, i’m not sure.
I know jQuery/JavaScript works in a similar manner.
Auto format is not tested fully i think. it has a lots of bugs.
Here is the link of the flash genious Senocular recommend to avoid autoformat.
http://www.senocular.com/index.php?id=1.398