1、屏幕显示:
全屏状态:
this.stage.displayState == "fullScreen"
最大化:
stage.nativeWindow.maximize();
最小化:同上使用
屏幕3显示判断:
stage.displayState = (stage.displayState != "fullScreen")?"fullScreen":"normal";
2、键盘事件:
private function EscKey(evt:KeyboardEvent):void{
if (evt.keyCode == Keyboard.F1 && evt.ctrlKey == true) //同时响应两个热键,这里为ctrl+F1
if (evt.keyCode == Keyboard.ESCAPE) //相应一个键盘事件,这里为ESC
}
3、控件与其父控件的大小
如下:
//this.stage.displayState == "fullScreen"; ----------------2@H_404_32@
var la:Label = new Label();
l@H_404_32@a.width=vb.width*0.9;@H_404_32@
vb.addChild(la);
this.stage.displayState == "fullScreen"; ----------------------1@H_404_32@
运行时,有可能当前显示的大小不对,这是Flex通常是normal下的格式,所以vb的width是在normal下大小,然后在全屏,此时,vb全屏了,可是vb的孩子la却还是当vb是normal下的width;应该修改为把1,放到2的位置,这样就ok了
4、Datagrid显示序号
<mx:DataGridColumn headerText="序号" labelFunction="GetOrder" width="50"/>
<Script>
@H_404_32@private function GetOrder(item:Object,column:DataGridColumn):String{
@H_404_32@var list:ArrayCollection = listPersons.dataProvider as ArrayCollection;
@H_404_32@var index:int = list.getItemIndex(item);
@H_404_32@return String(index+1);
@H_404_32@}
</Script>
private function init():void{
@H_404_32@var loader:Loader = new Loader();
@H_404_32@ @H_404_32@loader.contentLoaderInfo.addEventListener(Event.COMPLETE,prepareForSystray);
@H_404_32@ @H_404_32@loader.load(new URLRequest("assets/systray.png"));
}
private function windowClosing(evt:Event):void
@H_404_32@{
@H_404_32@evt.stopImmediatePropagation();
@H_404_32@evt.stopPropagation();
@H_404_32@evt.preventDefault();
@H_404_32@dock();
@H_404_32@}
private function closeApp(evt:Event):void
@H_404_32@{
@H_404_32@this.exit();
@H_404_32@}
@H_404_32@public function prepareForSystray(event:Event):void {
@H_404_32@
@H_404_32@//Retrieve the image being used as the systray icon @H_404_32@
@H_404_32@dockImage = event.target.content.bitmapData;
@H_404_32@
@H_404_32@//For windows systems we can set the systray props
@H_404_32@//(there's also an implementation for mac's,it's similar and you can find it on the net... ;) ) @H_404_32@
@H_404_32@if (NativeApplication.supportsSystemTrayIcon){
@H_404_32@setSystemTrayProperties();
@H_404_32@//Set some systray menu options,so that the user can right-click and access functionality
@H_404_32@//without needing to open the application
@H_404_32@SystemTrayIcon(NativeApplication.nativeApplication.icon).menu = createSystrayRootMenu(); @H_404_32@
@H_404_32@
@H_404_32@private function createSystrayRootMenu():NativeMenu{
@H_404_32@//Add the menuitems with the corresponding actions
@H_404_32@var menu:NativeMenu = new NativeMenu();
@H_404_32@var openNativeMenuItem:NativeMenuItem = new NativeMenuItem("显示");
@H_404_32@var exitNativeMenuItem:NativeMenuItem = new NativeMenuItem("退出");
@H_404_32@
@H_404_32@//What should happen when the user clicks on something...
@H_404_32@openNativeMenuItem.addEventListener(Event.SELECT,undock);
@H_404_32@exitNativeMenuItem.addEventListener(Event.SELECT,closeApp);
@H_404_32@
@H_404_32@menu.addItem(openNativeMenuItem);
@H_404_32@menu.addItem(new NativeMenuItem("",true));//separator
@H_404_32@menu.addItem(exitNativeMenuItem);
@H_404_32@
@H_404_32@return menu;
@H_404_32@
@H_404_32@private function setSystemTrayProperties():void{
@H_404_32@//Text to show when hovering of the docked application icon
@H_404_32@SystemTrayIcon(NativeApplication.nativeApplication.icon).tooltip = "公告板程序";
@H_404_32@
@H_404_32@//We want to be able to open the application after it has been docked
@H_404_32@SystemTrayIcon(NativeApplication.nativeApplication.icon).addEventListener(MouseEvent.CLICK,undock);
@H_404_32@
@H_404_32@//Listen to the display state changing of the window,so that we can catch the minimize @H_404_32@
@H_404_32@ @H_404_32@stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING,nwMinimized); //Catch the minimize event @H_404_32@ @H_404_32@
@H_404_32@}
@H_404_32@private function nwMinimized(displayStateEvent:NativeWindowDisplayStateEvent):void {
@H_404_32@if(displayStateEvent.afterDisplayState == NativeWindowDisplayState.MINIMIZED) {
@H_404_32@//Prevent the windowedapplication minimize action from happening and implement our own minimize
@H_404_32@//The reason the windowedapplication minimize action is caught,is that if active we're not able to
@H_404_32@//undock the application back neatly. The application doesn't become visible directly,but only after clicking
@H_404_32@//on the taskbars application link. (Not sure yet what happens exactly with standard minimize)
@H_404_32@displayStateEvent.preventDefault();
@H_404_32@
@H_404_32@//Dock (our own minimize)
@H_404_32@dock();
@H_404_32@}
@H_404_32@}
@H_404_32@public function dock():void {
@H_404_32@//Hide the applcation
@H_404_32@stage.nativeWindow.visible = false;
@H_404_32@
@H_404_32@//Setting the bitmaps array will show the application icon in the systray
@H_404_32@NativeApplication.nativeApplication.icon.bitmaps = [dockImage];
@H_404_32@ModelManager.SendMsg(ModelManager.BOARDOVER);
@H_404_32@
@H_404_32@public function undock(evt:Event):void {
@H_404_32@//After setting the window to visible,make sure that the application is ordered to the front,
@H_404_32@//else we'll still need to click on the application on the taskbar to make it visible
@H_404_32@stage.nativeWindow.visible = true; @H_404_32@
@H_404_32@stage.nativeWindow.orderToFront();
@H_404_32@stage.nativeWindow.activate();
@H_404_32@//Clearing the bitmaps array also clears the applcation icon from the systray @H_404_32@
@H_404_32@NativeApplication.nativeApplication.icon.bitmaps = [];
@H_404_32@this.stage.nativeWindow.maximize();
@H_404_32@//this.stage.displayState = "fullScreen";
@H_404_32@}
6、Flex显示的CSS(自定义的效果)效果必须定义在WindowedApplication中,其他地方不会显示的。
一个CSS效果:
<mx:Style>
@H_404_32@Alert {
@H_404_32@ titleStyleName: "alertTitle";
@H_404_32@ messageStyleName: "alertMessage";
@H_404_32@ buttonStyleName: "alertButton";
@H_404_32@ dropShadowEnabled: true;
@H_404_32@ shadowDistance: 5;
@H_404_32@ shadowDirection: right;
@H_404_32@ cornerRadius: 5;
@H_404_32@ background-color: #E9FFEA;
@H_404_32@}
@H_404_32@
@H_404_32@.alertTitle {
@H_404_32@ letterSpacing: 0;
@H_404_32@ fontSize: 16;
@H_404_32@ color: red;
@H_404_32@}
@H_404_32@
@H_404_32@.alertMessage {
@H_404_32@ letterSpacing: 0;
@H_404_32@ fontSize: 16;
@H_404_32@ fontWeight: normal;
@H_404_32@ color: black;
@H_404_32@}
@H_404_32@
@H_404_32@.alertButton {
@H_404_32@ letterSpacing: 0;
@H_404_32@ fontSize: 16;
@H_404_32@ cornerRadius: 10;
@H_404_32@ fontWeight: normal;
@H_404_32@}
ToolTip {
fontSize: 14;
fontWeight: normal;
backgroundColor: #22DD00;
dropShadowEnabled: true;
}
.body {
@H_404_32@ font-size: 12px;
@H_404_32@ font-family: Arial,Helvetica,sans-serif;
@H_404_32@ @H_404_32@filter: style=1,startY=0,finishY=100,startX=100,finishX=100;
@H_404_32@ @H_404_32@background-color: #666666;
@H_404_32@}
</mx:Style>
Flex自带的名称前面不加“.”,如果想要引用自定义css,则前面加“.”,然后在相应属性的stylename=“body”