Search code examples
testingactionscript-3

ActionScript: Questions about writing/compiling a block of code without a class or function?


  1. Having done some programming in Groovy, I know you can write test code in the Groovy console. I classify this as true a scripting language as it doesn't force you to have a class definition.

  2. So I'd assume with a name like ActionScript with 'script' in it's name that, you can write a series of statements that act linearly, such as a sequence of variables assignments, their manipulation and dumping out a value.

    My question is if this is possible, how do you go about doing it, in order to test some code with ActionScript3?

  3. Does the code have to exist in a package?

  4. Can the code exist on it's own? (If so, what would the name be you'd give to the source file in order to compile it from the command line?

    • Would you use mxmlc?

    • Would you use compc?

    • I've heard about fsch too. How about that?

    • I also read about a command called 'asc' in R.Braunstein's AS3 Bible 2nd ed (P8), but don't even see this in the SDK bin folders.... So what's that all about?

    • Assuming I've managed to compile this name.as file, how do I execute it and see results? Do I have to run it through a browser and the HTML template, or can I execute from a command line?

  5. Do you have to have a class in the source to bypass this?

  6. Can the code block be placed outside a dummy class?

  7. If so, does it have to exist in a function?

  8. Or can it exist on it's own?

  9. Does it have to exist in a code blocks, by wrapping them in curly braces?


Solution

    • 2: Code in frames (in Flash IDE) is like that, statements without any wrapping. But if you want interactive console, there is hardly any. With eval removed in AS 3.0, this is not easy to do.
    • 3: Code may exist outside of the package, and not only in frames:

      package {
        public class Open
        {
             //can use Hidden class
        }
      }
      
      //invisible for outer files
      class Hidden {}
      
    • 4: Code is compiled into swf or swc, entire project at time. SWF can be opened in Flash Player, although Flex applications will not work this way (and AIR apps need adl to run).

    • 5: ?
    • 6: yes
    • 7: no
    • 8: yes :)
    • 9: out-of-package code may exist with no curly braces.

    Overall, ActionScript is not so true script language as you might like. It is dynamic, but compiled and not really meant for interpretation.