单击按钮打开录音机

时间:2013-05-21 06:26:06

标签: flex air

我正在开发一个flex air应用程序(使用Windows 7 OS)。我想点击一个按钮打开我的Windows录音机软件(在配件部分)。我已经尝试了很多。但没有得到。有什么方法可以实现这一点吗?

1 个答案:

答案 0 :(得分:0)

您需要使用NativeProcess。查看http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/NativeProcess.html并查看示例代码。

修改链接的示例代码以满足您的需求,检查是否支持NativeProcess的完整代码以及运行录音机的方式如下:

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("%SystemRoot%\system32\SoundRecorder.exe");
            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());
        }
    }
}

希望有所帮助。