AIR程序启动画面,源代码是Joseph Labrecque写的,精简及修改了一部分代码,设置主程序的visible为false可以使启动窗口不在任务栏显示图标。Flex sdk 3.2, Air 1.5。
代码:Main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" visible=false
layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowSystemChrome;
import flash.display.NativeWindowType;
import flash.display.Screen;
privatevar splashTimer:Timer;
privatevar mainWindow:NativeWindow;
privatevar splashWindow:NativeWindow;
//只能是主程序的applicationComplete事件
privatefunction init():void {
mainWindow = this.stage.nativeWindow;
var splashWindowinitOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
splashWindowinitOptions.transparent = true;//启动屏幕背景透明
splashWindowinitOptions.systemChrome = NativeWindowSystemChrome.NONE;//无标题栏,状态栏
splashWindowinitOptions.type = NativeWindowType.UTILITY;//实用程序窗口
splashWindow = new NativeWindow(splashWindowinitOptions);
splashWindow.stage.scaleMode = 'noScale';
splashWindow.stage.align = 'topLeft';
splashWindow.stage.addChild(cvsSplash);//添加启动画面
splashWindow.x = (Screen.mainScreen.visibleBounds.width-cvsSplash.width)/2;
splashWindow.y = (Screen.mainScreen.visibleBounds.height-cvsSplash.height)/2;
splashWindow.activate();
//用timer控制,3秒钟后移除
splashTimer = new Timer(1000, 3);
splashTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeSplash);
splashTimer.start();
}
privatefunction removeSplash(e:TimerEvent):void {
mainWindow.x = (Screen.mainScreen.visibleBounds.width - mainWindow.width)/2;
mainWindow.y = (Screen.mainScreen.visibleBounds.height - mainWindow.height)/2;
//激活主程序窗口
mainWindow.activate();
splashWindow.stage.removeChild(cvsSplash);
splashWindow.close();
splashWindow = null;
splashTimer.stop();
splashTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, removeSplash);
splashTimer = null;
}
]]>
</mx:Script>
<mx:Label text="Application Loaded!" horizontalCenter="0" verticalCenter="0" fontWeight="bold" fontSize="36" color="#000000"/>
<mx:Canvas id="cvsSplash">
<mx:Image x="0" y="0" width="600" height="400" source="splash.png" scaleContent="false"/>
</mx:Canvas>
</mx:WindowedApplication>