7.4 Window 容器

Window 容器

Window组件是一个Flex容器,用于定义一个程序运行后出现所包含的内容和布局的操作系统窗口,也就是说它不同于初始或主窗口(如WindowedApplication或Application组件)。除此之外和WindowedApplication组件具有共同的功能,Window组件允许定义窗口的特性如窗口类型,样式,是否包含特定的窗口操作(如改变大小和最大化)。这些都是通过组件初始化时(还没有显示出来)设置其属性来访问,但是,一旦窗口打开后,这些属性将不能被设置和访问。

创建和使用Window容器

 <mx:Window>容器定义了包含自身的AIR程序对象。在MXML AIR程序里<mx:Window> 标签作为MXML部件的最顶层标签,MXML部件的文档内容作为window容器内容,Window 组件不能用在其他MXML文档中,只能通过ActionScript来创建组件实例。

因许多Window组件只能在window打开之前进行设置,所以其属性可以在 <mx:Window> MXML 标签中或用ActionScript代码进行设置。

一旦windows的初始属性设置完毕,调用Window组件的open() 方法后操作系统将会把它显示在用户桌面上。

下面是一个简单使用Window组件的例子,这个例子包含两个MXML文件,第一个使用Application容器且是程序的初始窗口,第二个使用Window容器作为程序的第二个窗口,在这个例子中,主窗口模拟一个应用程序的欢迎屏幕窗口,3秒后关闭欢迎屏幕且打开第二个窗口。

下面的代码定义主程序MXML文件,包含当程序运行时自动打开的初始化窗口(欢迎屏幕窗口):


<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  creationComplete ="init();" >
    
< mx:Script >
        
<![CDATA[
            private const LOAD_DELAY:int = 3;
            private var timeElapsed:int = 0;
            private var loadTimer:Timer;
            
            private var splashScreen:NativeWindow;
            private var docWindow:DocumentWindow;
            
            private function init():void
            {
                // center the window on the screen
                splashScreen = Shell.shell.openedWindows[0];
                var screenBounds:Rectangle = Screen.mainScreen.bounds;
                splashScreen.x = (screenBounds.width - splashScreen.width) / 2;
                splashScreen.y = (screenBounds.height - splashScreen.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;
                    
                    splashScreen.close();
                    
                    // open a new instance of the document window
                    docWindow = new DocumentWindow();
                    docWindow.open();
                }
            }
            
            private function updateStatus():void
            {
                loadStatusMessage.text = "initializing...  " + (LOAD_DELAY - timeElapsed).toString() + " seconds remaining.";
            }
        
]]>
    
</ 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文件中,其顶层标签为<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 >  

关于Window容器的更多信息,请参阅Flex 3 语言参考

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值