isFirstRun AS3 Air applicationUpdaterUI

时间:2014-09-06 23:46:12

标签: actionscript-3 air

我正在尝试创建一个自动检查更新的更新程序,然后自动下载并安装,然后在安装后检查首次运行事件。我想这样,所以当有人下载​​新版本时,我可以重置软件的试用版。

我让autoupdate正常工作,但在某个地方搞砸了。我不明白这里的操作顺序,特别是对于initialize()方法。在API中它显示了一个isFirstRun布尔值,这意味着它会在所有内容已经下载并安装完毕后进行检查。关于使这项工作的任何建议......首先让它下载更新并将isFirstRun布尔值设为TRUE

import air.update.ApplicationUpdaterUI;
import flash.filesystem.File;
import air.update.events.StatusUpdateEvent;
import air.update.events.*;

var appWindow:NativeWindow = this.stage.nativeWindow;
//Code for making Dialog Boxes---from http://thirdroute.com/2011/12/native-alerts-in-air/  AND http://www.purplesquirrels.com.au/2012/03/simple-way-to-get-native-alerts-with-adobe-air/
import flash.html.HTMLLoader;
var alertDispatcher:HTMLLoader = new HTMLLoader();
var _html:String ="<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'>" +
                    "<title></title><script></script></head><body></body></html>";
alertDispatcher.loadString(_html); //End of Code for Dialog Boxes.

var appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI(); 
appUpdater.updateURL = "http://www.postureviewer.com/update/updateDescriptor.xml" ;
appUpdater.delay = 0;
appUpdater.initialize();
appUpdater.isCheckForUpdateVisible = false;

versionNumberTxt.text = appUpdater.currentVersion;

appUpdater.addEventListener(UpdateEvent.INITIALIZED, appUpdaterComplete);
appUpdater.addEventListener(ErrorEvent.ERROR, onError);

function appUpdaterComplete(e:UpdateEvent) {
    appUpdater.checkNow();
    if (appUpdater.isFirstRun) {
        alertDispatcher.window.alert("First Run");
    } else {
        alertDispatcher.window.alert("No...Not First Run");
    }
}
function onError(event:ErrorEvent):void 
{ 
    alertDispatcher.window.alert("Error: "+event);
}

2 个答案:

答案 0 :(得分:0)

如果您在到期前提供具有指定数量的允许运行的试验,那么您可以在完成时将用户可用的试运行次数重置为0,或者如果继续,则通过添加试运行已经使用过。同样地,允许的天数,日期等

答案 1 :(得分:0)

我改变了事件监听器的位置,并删除了if语句的else部分。现在它有效。让我困惑的部分是当INITIALIZED事件被解雇时。当更新全部完成并重新启动空中程序后,它会立即触发更新并再次触发。这是我第二次有兴趣捕获&#34; isFirstRun&#34;事件。我不希望它让我知道它根本不是第一次运行。

import air.update.ApplicationUpdaterUI;
import flash.filesystem.File;
import air.update.events.StatusUpdateEvent;
import air.update.events.*;

var appWindow:NativeWindow = this.stage.nativeWindow;
//Code for making Dialog Boxes---from http://thirdroute.com/2011/12/native-alerts-in-air/  AND http://www.purplesquirrels.com.au/2012/03/simple-way-to-get-native-alerts-with-adobe-air/
import flash.html.HTMLLoader;
var alertDispatcher:HTMLLoader = new HTMLLoader();
var _html:String ="<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'>" +
                    "<title></title><script></script></head><body></body></html>";
alertDispatcher.loadString(_html); //End of Code for Dialog Boxes.

var appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI(); 
appUpdater.updateURL = "http://www.postureviewer.com/update/updateDescriptor.xml" ;
appUpdater.delay = 0;
appUpdater.addEventListener(UpdateEvent.INITIALIZED, appUpdaterComplete);
appUpdater.addEventListener(ErrorEvent.ERROR, onError);

appUpdater.initialize();
appUpdater.isCheckForUpdateVisible = false;

versionNumberTxt.text = appUpdater.currentVersion;

function appUpdaterComplete(e:UpdateEvent) {
    appUpdater.checkNow();
    if (appUpdater.isFirstRun) {    //This only evaluates to true after an update has occurred...
        alertDispatcher.window.alert("First Run");
    }
}
function onError(event:ErrorEvent):void 
{ 
    alertDispatcher.window.alert("Error: "+event);
}