Any way to have an ActionScript 3 (Flex/AIR) project print to standard output?

十年热恋 提交于 2019-12-01 01:27:54

问题


Is there any way to have a binary compiled from an ActionScript 3 project print stuff to stdout when executed?

From what I've gathered, people have been going around this limitation by writing hacks that rely on local socket connections and AIR apps that write to files in the local filesystem, but that's pretty much it -- it's obviously not possible with the Flash Player and AIR runtimes from Adobe.

Is there any project (e.g. based on the Tamarin code) that is attempting to implement something that would provide this kind of functionality?


回答1:


With AIR on Linux, it is easy to write to stdout, since the process can see its own file descriptors as files in /dev.

For stdout, open /dev/fd/1 or /dev/stdout as a FileStream, then write to that.

Example:

var stdout : FileStream = new FileStream();
stdout.open(new File("/dev/fd/1"), FileMode.WRITE);
stdout.writeUTFBytes("test\n");
stdout.close();

Note: See this answer for the difference between writeUTF() and writeUTFBytes() - the latter will avoid garbled output on stdout.




回答2:


As you say, there's no Adobe-created way to do this, but you might have better luck with Zinc, it is similar to AIR but provides real OS integration of Flash-based applications. Look though the API docs, there should be something there.




回答3:


If you are using a debug Flash Player, you can have the Flash Player log trace messages to a file on your system.

If you want real time messages, then you could tail the file.

More info:

http://blog.flexexamples.com/2007/08/26/debugging-flex-applications-with-mmcfg-and-flashlogtxt/

mike chambers

mesh@adobe.com




回答4:


Redtamarin seems to be able to do this (even though it's still in its infancy):

Contents of test.as:

import avmplus.System;
import redtamarin.version;

trace( "hello world" );
trace( "avmplus v" + System.getAvmplusVersion() );
trace( "redtamarin v" + redtamarin.version );

On the command line:

$ ./buildEXE.sh test.as 

test.abc, 243 bytes written
test.exe, 2191963 bytes written

test.abc, 243 bytes written
test.exe, 2178811 bytes written

$ ./test
hello world
avmplus v1.0 cyclone (redshell)
redtamarin v0.1.0.92


来源:https://stackoverflow.com/questions/38651/any-way-to-have-an-actionscript-3-flex-air-project-print-to-standard-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!