如何使用actionscript 3.0从我的flash文件中单击按钮来启动.exe文件?

时间:2014-07-14 19:05:01

标签: actionscript-3 flash-cs5

每当我点击按钮时,我想调用我的exe文件。我目前正在使用flash CS5.5.someone,请帮帮我?

1 个答案:

答案 0 :(得分:0)

作为Web应用程序,这是不可能的。

虽然我会建议您不要使用此策略,但如果您定位AIR或投影机,则可以完成此操作。

两者都有警告,所以一定要了解各自的技术限制。

投影

Project使用flash.system包来执行fscommand

import flash.system.fscommand;
fscommand("exec", "app.exe");

AIR

AIR应用程序应使用flash.desktop包来调用NativeProcess

NativeProcessExample.as示例,根据Adobe ASDoc页面:

package {
import flash.display.Sprite;
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.events.NativeProcessExitEvent;
import flash.filesystem.File;

public class NativeProcessExample extends Sprite {
    public var process:NativeProcess;

    public function NativeProcessExample() {
        if (NativeProcess.isSupported) {
            setupAndLaunch();
        }
        else {
            trace("NativeProcess not supported.");
        }
    }

    public function setupAndLaunch():void {
        var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
        var file:File = File.applicationDirectory.resolvePath("test.py");
        nativeProcessStartupInfo.executable = file;

        var processArgs:Vector.<String> = new Vector.<String>();
        processArgs[0] = "foo";
        nativeProcessStartupInfo.arguments = processArgs;

        process = new NativeProcess();
        process.start(nativeProcessStartupInfo);
        process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
        process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
        process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
        process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
        process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
    }

    public function onOutputData(event:ProgressEvent):void {
        trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
    }

    public function onErrorData(event:ProgressEvent):void {
        trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
    }

    public function onExit(event:NativeProcessExitEvent):void {
        trace("Process exited with ", event.exitCode);
    }

    public function onIOError(event:IOErrorEvent):void {
        trace(event.toString());
    }
}
}