views:

510

answers:

6

I'd like to be able to write a .swf file that is runnable as a command line app. In other words, I would be able to create actionscript classes which can interact with stdin and stdout, and could then execute that .swf directly in the command line.

I suspect that this isn't really possible. Can anyone confirm that?

EDIT: A couple of the answers pointed out that using Flash for command line work probably isn't the best choice. I wholeheartedly agree in most situations. The reason I am asking about this is because I want to do some AS3 code generation, and reflecting on AS3 classes within the runtime would be easier than parsing the code or walking the intermediary XML that asdoc produces. I'm doing the XML approach now in Ruby, but would love to have a cleaner solution!

+4  A: 

Nope--not possible. The best you can do is a standalone app (which can be made in Flash or with a Projector version of flash player, available from the Adobe website).

And why would you want to--Flash is awesome because of the great GUI capabilities. There are plenty of other programming languages that are much better suited for the command line (Python or Ruby or, god forbid, even Perl)

zenazn
thanks for the response. I added an explanation to me question as to why I wanted to use as3 on the command line.
Pete Hodgson
+4  A: 

Apparently there is the Tamarin project which aims to create an open source implementation of AS3. This page gives a little detail of compiling an AS3 script and running it from a command line.

I'm not getting a good idea of how stable Tamarin is, but it might be your best bet for now. On the other hand, I have to strongly agree with @zenazn that you would be better off long-term learning a language more designed for general purposes, but if really want to just use Actionscript, don't let anyone stop you :)

Mark Rushakoff
Tamarin IS the AVM2 Virtual Machine that executes compiled ActionScript opcode (ABC, or Actionscript Byte Code) within Flash Player 9+. Adobe has donated this VM to the Mozilla foundation in the hope they will integrate it with FireFox to JIT compile (Just In Time) Javascript to ABC for much faster execution within the browser. Similar to what Google are doing with Chrome/Chromium.
Luke
+1  A: 

There's no way to do this with a bare SWF right now.

However, you can publish your Flash content as an AIR app. The app can then be invoked from the command line, and you can collect the arguments from the arguments property of an InvokeEvent. The basic idea looks like this:

NativeApplication.nativeApplication.addEventListener( 
            InvokeEvent.INVOKE, onInvoke );
// ...
function onInvoke( e:InvokeEvent ) {
    var numArguments:int = e.arguments.length;
    // ...
}

Note, however, that this is essentially a one-way street. You can grab the command-line arguments, but Flash still doesn't grok the idea of stdin and stdout.

fenomas
A: 

You could have a look at haXe with is very similar to AS3 and could compile NekoVM Bytecode, which could be run on the command line.

Also interesting could be HippoHX, it is a kind of framework to create desktop applications out of flash movies. (similar to AIR, but with full access to the system.)

Hippo
A: 

If you are really that inclined, you could open a local socket, and then have a helper program, running from the command-line communicate with the open SWF.

This might be a good time to learn another language. May I suggest Java?

PiPeep
+1  A: 

Actually, there is a project that makes it possible. RedTamarin is a project that extends AS3 (technically, the Tamarin project which is the Adobe/Mozilla ECMAScript project) to have access to low-level libraries (ie. POSIX). In its current state it appears to be good for stuff like shell-scripting-like programs which is what it sounds like what you're looking for.

Give it a try:

http://code.google.com/p/redtamarin/

RickDT