AIR Native Process适用于Mac,但不适用于Windows

时间:2017-06-06 02:54:26

标签: windows flash air

我正在使用Flash CC构建AIR应用程序,以便我可以使用本机进程。在我将它集成到我的完整项目之前,我创建了一个小型测试项目,看看它是否可行。我在Windows中尝试过它并没有用。我切换到Mac并让它在那里工作。

本地流程由按键触发。该文件作为Windows安装程序发布,而不是Air包。我确保在xml文件中包含extendedDesktop。我仔细检查了文件路径。还有其他原因吗?

package  {

    import flash.display.MovieClip;
    import flash.filesystem.File;
    import flash.events.KeyboardEvent;
    import flash.desktop.NativeProcess;
    import flash.desktop.NativeProcessStartupInfo;


    public class Main extends MovieClip {

        var exe:File = new File("C:\Windows\System32\notepad.exe");
        var nativeProcess:NativeProcess = new NativeProcess();
        var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
        var args:Vector.<String> = new Vector.<String>();

        public function startProcess(event:KeyboardEvent):void
        {
            if (event.keyCode == 65) {
                nativeProcessStartupInfo.executable = exe;
                args.push("C:/Users/Tristan/Documents/TVCR/airTestFile.rtf");
                nativeProcessStartupInfo.arguments = args;
                nativeProcess.start(nativeProcessStartupInfo);
            }
        }
    }   
}

3 个答案:

答案 0 :(得分:0)

如何输出一些调试信息。如果键盘事件确实触发了处理程序方法,以下代码将显示一些消息。

public function startProcess(event:KeyboardEvent):void
{
    // LogText:TextField
     LogText.appendText("\n\nKey Pressed: " + event.keyCode);
}

如何输出和诊断异常:

try
{
    nativeProcess.start(nativeProcessStartupInfo);
    LogText.appendText("\n\nThe process has been started without exceptions.");
}
catch (fail:Error)
{
    // LogText:TextField
    LogText.appendText("\n\n" + fail.getStackTrace());
}

答案 1 :(得分:0)

似乎我使用的文件路径格式不正确。

C:\Windows\System32\notepad.exe

应该是

C:\\Windows\\System32\\notepad.exe

答案 2 :(得分:0)

Windows的文件路径必须使用双反斜杠&#34; \&#34;因为单个反斜杠被解释为转义。

方便的东西,特别是如果您需要构建可执行文件的路径,或者您要制作的东西是Windows和Mac,那就是使用File.separator,因为它会做& #34; \&#34;适用于Windows和&#34; /&#34;对于Mac / Linux

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#separator

相关问题