flex自动更新脚本显示错误

时间:2009-09-10 09:35:05

标签: flex air

我想在flex3中启用自动更新脚本。我正在使用下面的代码来执行此操作,但是当我将鼠标悬停在红色标记上时,弹性编辑器在第39行显示红色标记,编辑器显示错误:

1046:未找到类型或不是编译时常量:UpdateEvent。

我该如何删除此错误。请指导我。

         

    // Instantiate the updater
    private var appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI();

    private function checkForUpdate():void {
        // The code below is a hack to work around a bug in the framework so that CMD-Q still works on MacOS
        // This is a temporary fix until the framework is updated
        // See http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&catid=670&threadid=1373568
        NativeApplication.nativeApplication.addEventListener( Event.EXITING, 
            function(e:Event):void {
                var opened:Array = NativeApplication.nativeApplication.openedWindows;
                for (var i:int = 0; i < opened.length; i ++) {
                    opened[i].close();
                }
        });    

        setApplicationVersion(); // Find the current version so we can show it below

        // Configuration stuff - see update framework docs for more details
        appUpdater.updateURL = "http://www.mytoplinks.net/flex/update.xml"; // Server-side XML file describing update
        appUpdater.isCheckForUpdateVisible = false; // We won't ask permission to check for an update
        appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate); // Once initialized, run onUpdate
        appUpdater.addEventListener(ErrorEvent.ERROR, onError); // If something goes wrong, run onError
        appUpdater.initialize(); // Initialize the update framework
    }

    private function onError(event:ErrorEvent):void {
        Alert.show(event.toString());
    }

    private function onUpdate(event:UpdateEvent):void {
        appUpdater.checkNow(); //Go check for an update now
    }

    // Find the current version for our Label below
    private function setApplicationVersion():void {
        var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
        var ns:Namespace = appXML.namespace();
        ver.text = "Current version is " + appXML.ns::version;
    }
]]>
</mx:Script>

<mx:VBox backgroundColor="blue" x="0" y="0" width="100%" height="100%">
    <mx:Label color="white" id="ver" />
</mx:VBox>

1 个答案:

答案 0 :(得分:1)

将UpdateEvent的导入添加到脚本部分的顶部

import air.update.events.UpdateEvent;

HTH

柯恩