Great ActionScript Site

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:

  1. var s:Sprite = new Sprite;
  2. with( beginFill(0xFF0000), drawCircle(0,0,500);
  3. addChild(s);

Can anyone shed light on that?

This entry was posted in links and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Michel Nielsen
    Posted September 26, 2009 at 3:55 am | Permalink

    Hey Zevan

    Actually there isn’t much to say. ActionScript allows both formats if no arguments are passed to the constructor.

  2. Posted September 26, 2009 at 7:48 am | Permalink

    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.

  3. Posted September 26, 2009 at 9:21 am | Permalink

    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…

  4. Posted September 26, 2009 at 10:29 am | Permalink

    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.

  5. Posted September 26, 2009 at 3:59 pm | Permalink

    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:

    var x:int = 1;
    var s:Sprite = new Sprite x--;

    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.

  6. DieTapete
    Posted September 27, 2009 at 4:02 am | Permalink

    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.

  7. Posted September 27, 2009 at 6:42 am | Permalink

    @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).

  8. pJoe
    Posted September 29, 2009 at 9:44 am | Permalink

    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. ;]

  9. Posted September 29, 2009 at 5:56 pm | Permalink

    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.

  10. Sureshdavid
    Posted December 24, 2009 at 3:21 am | Permalink

    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.

Post a Comment

Your email is never published nor shared. Required fields are marked *