将 AIR 文件下载到用户的计算机

为了使用 Updater 类,用户或应用程序必须先在本地将 AIR 文件保存到用户的计算机。

注: AIR 1.5 包括一个更新框架,该框架可帮助开发人员在 AIR 应用程序中提供良好的更新功能。使用此框架比直接使用 Updater 类的 update() 方法简单许多。有关详细信息,请参阅 使用更新框架

以下代码从一个 URL (http://example.com/air/updates/Sample_App_v2.air) 读取 AIR 文件,然后将该 AIR 文件保存到应用程序存储目录中。

ActionScript 示例:

var urlString:String = "http://example.com/air/updates/Sample_App_v2.air"; 
var urlReq:URLRequest = new URLRequest(urlString); 
var urlStream:URLStream = new URLStream(); 
var fileData:ByteArray = new ByteArray(); 
urlStream.addEventListener(Event.COMPLETE, loaded); 
urlStream.load(urlReq); 
 
function loaded(event:Event):void { 
    urlStream.readBytes(fileData, 0, urlStream.bytesAvailable); 
    writeAirFile(); 
} 
 
function writeAirFile():void { 
    var file:File = File.applicationStorageDirectory.resolvePath("My App v2.air"); 
    var fileStream:FileStream = new FileStream(); 
    fileStream.open(file, FileMode.WRITE); 
    fileStream.writeBytes(fileData, 0, fileData.length); 
    fileStream.close(); 
    trace("The AIR file is written."); 
}

JavaScript 示例:

var urlString = "http://example.com/air/updates/Sample_App_v2.air"; 
var urlReq = new air.URLRequest(urlString); 
var urlStream = new air.URLStream(); 
var fileData = new air.ByteArray(); 
urlStream.addEventListener(air.Event.COMPLETE, loaded); 
urlStream.load(urlReq); 
 
function loaded(event) { 
    urlStream.readBytes(fileData, 0, urlStream.bytesAvailable); 
    writeAirFile(); 
} 
 
function writeAirFile() { 
    var file = air.File.desktopDirectory.resolvePath("My App v2.air"); 
    var fileStream = new air.FileStream(); 
    fileStream.open(file, air.FileMode.WRITE); 
    fileStream.writeBytes(fileData, 0, fileData.length); 
    fileStream.close(); 
    trace("The AIR file is written."); 
}

有关详细信息,请参阅: