AIR(window容器示例之闪屏)

Window 容器示例

以下示例显示 Window 组件的基本用法。示例包括两个 MXML 文件。第一个文件使用 WindowedApplication 容器,是应用程序的初始窗口。第二个文件使用 Window 容器,以定义应用程序的辅助窗口。在此示例中,主要窗口模拟应用程序的“闪屏”。在设定的时间(4 秒)之后,它关闭闪屏并打开第二个窗口为了使闪屏窗口不带窗口镶边,在 application.xml 文件中将 systemChrome 标签设置为 none。

 

以下代码定义主应用程序 MXML 文件,此文件包含运行应用程序时自动打开的初始窗口(闪屏):

 

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"    showFlexChrome="false"
creationComplete="init();">
<mx:Script>
<![CDATA[
  private const LOAD_DELAY:int = 4;
  private var timeElapsed:int = 0;
  private var loadTimer:Timer;
  private var docWindow:DocumentWindow;
  private function init():void
    {
       // center the window on the screen
       var screenBounds:Rectangle = Screen.mainScreen.bounds;
      nativeWindow.x = (screenBounds.width - nativeWindow.width) / 2;
      nativeWindow.y = (screenBounds.height - nativeWindow.height) / 2;
      // start the timer, which simulates a loading delay
      loadTimer = new Timer(1000);
      loadTimer.addEventListener(TimerEvent.TIMER, incrementTime);
      loadTimer.start();
      updateStatus();
}
private function incrementTime(event:TimerEvent):void
{
     timeElapsed++;
     updateStatus();
     // if the loading delay has passed, stop the timer,
     // close the splash screen, and open the document window
     if ((LOAD_DELAY - timeElapsed) == 0)
      {
         loadTimer.stop();
         loadTimer.removeEventListener(TimerEvent.TIMER, incrementTime);
         loadTimer = null;
         nativeWindow.close();
         // open a new instance of the document window
         docWindow = new DocumentWindow();

         docWindow.open();
        }
}
private function updateStatus():void
{
         var timeRemaining:uint = LOAD_DELAY - timeElapsed;
         var timeRemainingMsg:String = timeRemaining.toString() + " second";
         if (timeRemaining != 1) { timeRemainingMsg += "s"; }
         timeRemainingMsg += " remaining.";
         loadStatusMessage.text = "initializing... " + timeRemainingMsg;
}
]]>
</mx:Script>
       <mx:VBox horizontalCenter="0" verticalCenter="0">
          <mx:Text text="My Splash Screen" fontFamily="Courier New" fontSize="36"/>
          <mx:Text id="loadStatusMessage" text="initializing..."/>
        </mx:VBox>
</mx:Application>


每秒调用一次 incrementTime() 方法,当达到合适时间时则创建 DocumentWindow 实例,并调用其 open() 方法。
DocumentWindow 类定义于单独的 MXML 文档中。其基础 MXML 标签是 <mx:Window> 标签,因此它是Window 类(Window 组件)的子类。

 

下面是 DocumentWindow MXML 文件的源代码:


<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml"
  layout="absolute"
  title="Document window"
  width="550" height="450">
<mx:Text text="This is a document window." horizontalCenter="0" verticalCenter="0"/>
</mx:Window>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值