Using the New Inline Metadata in ASC2

Posted on September 28, 2012 | 4 comments

UPDATE: There are ASC2 changes to the [Inline] feature since preview 3 (Oct 8th)

There are many changes coming to tooling around ActionScript. One of the latest changes is something you can find in the release of Flash Builder 4.7. It’s the new ActionScript compiler, aka ASC2. Thibault does a great introduction blog post on the new compiler.

ASC2 has a lot going on, from better compiler times to supporting the new ActionScript worker API. The ASC2 is in beta and will continue to be improved over time. The feature I wanted to highlight in this post was the new metadata tag [Inline]. At first I thought this would be a great way to speed up a lot of code, but it depends on the content and has some restrictions.

Lee Brimelow does a great job in this video showing how to get it working in Flash Builder 4.7. The video also demonstrates how the [Inline] tag works.

To use the new metadata [Inline] tag you need need to tell the ASC2 compiler to using inlining with a -inline compiler argument. Here is a quick look at some of those requirements for the [Inline] tag to work:

  • The function is final, static or the containing scope is file or package
    Compiler Error Message:

    The function myFunction could not be inlined, as only functions marked as final, static or global functions can be inlined.

  • The function does not contain any activations
  • The function does not contain any try or with statements
  • The function does not contain any function closures
  • Changed in preview 3 if using [Inline] not limited to 50 expressions.The function body contains less than 50 expressions
    Compiler Error Message:

    The function myFunction could not be inlined, as it contains 51 expressions. No more than 50 expressions can be in the function body.

I went through and tried the requirements listed above in Flash Builder 4.7 and ASC2 to get the compiler error messages above. Not all scenarios had compiler error messages, so you’ll want to double check your code to see if the inline is really working, Lee shows a way to do it with a decompiler in his video.

If you do start using ASC2 and find some differences with your application versus compiling with mxmlc you’ll want to check out the backward compability list here –

  • Pingback: @renaun posts: Using the New Inline Metadata in ASC2 « eaflash

  • Andre Michelle

    Adding -inline completely messes up a lot of code that was working before in ASC1. It just don’t work. Here is an example I could extract from our project:

    • renaun

      Not sure. In the pastebin I do not see any [Inline] metadata so I assume you are not trying to inline this particular code, correct? By the pastebin I also can’t understand what the bug is.

      • Andre Michelle

        There is no need to inline ANYTHING. Just by passing -inline as a compiler argument, the bytecode gets messed up. Put both classes in your src folder and run the Application class. There are obviously numerous of problems with inline out there. I’d love to help, but I need a serious contact person.

        • renaun

          I was thrown off by the top static function in pastebin. I created an and file and compiled and run with and without the -inline argument. I can verify that the code runs differently.
          I also verified that if I set to non-final it works as expected. Or set IssuedClass to final but add [Inline] to the static getNameByKey() it work as expected.

          Either way though this looks like a bug.