查找应用名称

Find name of app

FlashBuilder Flex

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

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

只要应用的名称不变就可以使用

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

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

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

您应该能够使用阶段的 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
    }
}

重启函数代码如下:

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,我忘记了密码)