Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

apache flex - Is it possible to create a 'command line' swf?

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

YES! It actually is possible.

You can create a pure AS3 AIR project (without any application window) and run from the command line using ADL (AIR Debug Launcher).

ADL will execute your SWF and will pass whatever arguments you give it directly to your application at runtime—all from the command line! To read the arguments from AS3 just add this code to your main class:

package
{
   import flash.desktop.NativeApplication;
   import flash.display.Sprite;
   import flash.events.InvokeEvent;

   public class CmdLine extends Sprite
   {
      public function CmdLine()
      {
         NativeApplication.nativeApplication.addEventListener(
            InvokeEvent.INVOKE, onInvokeEvent); 

         function onInvokeEvent(invocation:InvokeEvent):void { 
            trace(invocation.arguments); 
         } 
      }
   }
}

Your main class will still extend Sprite, but you won't see any UI unless you create NativeWindow objects. If you're using Flash Builder, just create a new AIR project and rename the extension of the main .mxml file to .as (before you finish the wizard).

Here is more about ADL: Using the AIR Debug Launcher (ADL)

Also, this will be very useful: AIR application invocation and termination

You can do all your output using trace(), write files, or even write directly to stdout, as seen here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...