compiling actionscript from command line using MXMLC
Asked Answered
V

5

17

I have a tiny actionscript "project" consisting of two files, call them foo.as and bar.as. For reasons I won't go into, I really really want to build the .SWF from the command line, without setting up a formal project of any kind. Every compiler I've ever used lets you do this, but for the life of me I can't figure out how to coerce MXMLC into compiling these two files and linking them into a SWF.

Naively, I try

MXMLC foo.as bar.as

but I'm informed that only one source file is allowed.

Ok, supposing I compiled these two files separately, how would I link them together to get the final SWF?

NOTE: The only reason I have two files instead of one is the requirement of only one class per file. I tried putting both classes in one file and making one of the classes private or internal but neither of these ideas worked. I would be ecstatic to find out I can put more than one class in a file (with only one being public).

Vansickle answered 20/5, 2009 at 4:0 Comment(0)
F
22

This is a two part question, so I will answer both separately.

Compiling two class files into one SWF

MXMLC will automagiclly compile all classes it finds from the entry point you give it (your main class). It finds classes from your import statements, and full class path definitions.

Here is a really good guide for using MXMLC command line to compile your AS3 projects. The article is a bit dated, but the information is still good. He goes into detail about the things you need to know when using the command line compiler, including the MXMLC options, writing BAT scripts, and a bit about AS3 that you can probably skip if you know what your doing.

Having more than one class in a file

AS3 allows you to have one class per file, plus as much "helper" classes as you like. It does not support protected and private classes like Java does. Helper classes are only visible in the file they are defined.

Helper classes sit outside the package declaration (which is a little weird to me). Here is an example:

package com.mynamespace
{
     public class Foo 
     {
          private var _fooHelper:FooHelper = new FooHelper();
     }
}

// helper class imports also go outside the package.
import com.example.xml.SaxHandler;
class FooHelper
{
     private var bar:Number = Math.random();
}
Fez answered 20/5, 2009 at 21:2 Comment(0)
B
2

If the main file/class needs/uses the class of the other file, the other file will also be compiled into the swf.

Biggin answered 20/5, 2009 at 11:29 Comment(0)
E
2

As Hippo says, the compiler will automatically compile into the SWF all the classes used through your code, it's recursive by default.

You can read also all the options the MXMLC compiler has.

Edmundson answered 20/5, 2009 at 12:46 Comment(0)
A
0

If you're interested in automating that process, you can also use Project Sprouts which includes quite a bit more than you're asking for - but does give you the ability to kick off builds and test runs from the terminal.

Affricate answered 5/7, 2009 at 19:31 Comment(0)
P
0

If you're using grunt as a task manager (for js), you can use this plugin:

https://github.com/JamesMGreene/grunt-mxmlc

You set config options then run it from command line:

grunt.initConfig({
  mxmlc: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})
Payable answered 13/3, 2014 at 3:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.