【问题标题】:Find name of app查找应用名称
【发布时间】:2017-05-17 16:25:02
【问题描述】:

FlashBuilder 弹性

在我的重启代码中,我有以下行:

var file:File = File.applicationDirectory.resolvePath("app:/playerAir.exe");

只要应用名称不变,它就可以工作

我想要一种自动查找此应用名称的方法来更改 "playerAir"

原因: 如果我更改名称,我也必须在重启功能中更改它 如果客户端有多个版本的文件(playerAir.exeplayerAir1.exeplayerAir2.exe),那么它会启动错误的版本。

我怎样才能使它根据应用程序的名称进行相应的更改?

【问题讨论】:

  • 您找到解决方案了吗?
  • 是的,不幸的是,由于该项目不是我的,我无法再访问它了。解决方案就是您所说的多行或 2 行。
  • 如果你能回忆起额外的一两行,如果你分享它,它可能会对未来的访问者有所帮助。如果您觉得我的回答满足了这个问题,请考虑将其标记为已接受的答案,这有助于有类似问题的人更快地找到解决方案 - 它还可以提高您和我的声誉。

标签: actionscript-3 reboot


【解决方案1】:

reboot函数代码如下:

public function Reboot():void                                                                   ///
        {                                                                                               ///
            var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();     ///
            var app:WindowedApplication=WindowedApplication(FlexGlobals.topLevelApplication);           ///
            var swf:String=stage.loaderInfo.url.substring(0,stage.loaderInfo.url.lastIndexOf("/")+1);   ///get swf's path (- *name*.swf)
            swf=swf+app.applicationID;                                                                  ///adds applicationID after the path. ex: app:/ -> becomes -> app:/m7tvPlayerAir
            var d:Array = File.applicationDirectory.getDirectoryListing();                              ///get all files in the directory
            var exe:String;                                                                             ///the executable (.exe, .app, .dmg) (multiplatform)
            for each(var f:File in d){                                                                  ///checks all files in the directory
                if(f.url.indexOf(swf)==0 && (f.url.indexOf(".dmg") > -1 || f.url.indexOf(".app") > -1 || f.url.indexOf(".exe") > -1)){///if any of them has the same directory and name, and has 1 of the extensions
                    exe=f.url;                                                                          ///found the executable
                    break;                                                                              ///stops the loop
                }///end If
            }///end for
            trace(exe);                                                                                 ///
            if(exe==null){                                                                              ///will just close the application if it doesn't find the file
                (FlexGlobals.topLevelApplication).exit();                                               ///
            }else{                                                                                      ///if it did find a file
                var file:File = File.applicationDirectory.resolvePath(exe);                             ///
                nativeProcessStartupInfo.executable = file;                                             ///
                nativeProcessStartupInfo.workingDirectory = File.documentsDirectory;                    ///
                var process:NativeProcess = new NativeProcess();                                        ///
                (FlexGlobals.topLevelApplication).exit();                                               ///
                process.start(nativeProcessStartupInfo);                                                ///
            }///end else
        }///end function

(嘿,我是 Ohciarob,我忘记密码了)

【讨论】:

    【解决方案2】:

    您应该能够使用舞台的loaderinfo 对象的url 属性来确定应用程序名称。

    这将指向正在运行的 swf 文件,默认情况下与可执行文件同名。

    因此,如果您知道您的应用具有 .exe 扩展名,这可能会起作用:

    var path:String = stage.loaderInfo.url.replace(".swf",".exe");
    var file:File = File.applicationDirectory.resolvePath(path);
    

    如果您正在运行一个多平台应用程序,您可以在应用程序目录中查找合适的应用程序扩展:

    //get the swf path minus the 'swf'
    var swf:String = stage.loaderInfo.url.substring(0,stage.loaderInfo.url.lastIndexOf(".") + 1);
    
    //get all the files in the application directory
    var d = File.applicationDirectory.getDirectoryListing();
    
    //find your executable (this is just a sample of how to do this, ideally you'd have a compile time constant to indicate the extension of your current build)
    var exe:String;
    for each(var f:File in d){
        if(f.url.indexOf(swf) === 0 && (f.url.indexOf(".dmg") > -1 || f.url.indexOf(".app") > -1 || f.url.indexOf(".exe") > -1)){
            exe = f.url; //found the executable path
            break; //stop the loop
        }
    }
    

    【讨论】:

    • 假设我在 Linux 或 MacOS 上运行 AIR 应用程序。在这些系统上,EXE 中没有二进制文件。你的举动?
    • @Organis - OP 并未表明这是一个多平台应用程序。如果您有有用的建议,请务必提出建议。
    • 在问你之前,我搜索了最合乎逻辑的想法,即 NativeApplication 和 NativeProcess,但似乎没有关于 AIR 进程的启动信息,或者它隐藏在某个不那么明显的地方。这就是我问的原因。
    • 我从来没有在旅行的任何地方偶然发现它,如果它在那里,它没有记录(或者至少没有很好地记录)。也许其他人会提出比这更优雅的解决方案,或者知道找到应用程序名称的显式方法。
    • 如果 swf 没有改变它的名字,但是 exe 改变了怎么办?有什么办法查吗?我可能已经想通了,现在测试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 2012-03-04
    • 1970-01-01
    相关资源
    最近更新 更多