Flex air window的定制

来源:互联网 发布:去眼袋眼霜 知乎 编辑:程序博客网 时间:2024/05/29 07:31
下面是我对Window类的一个定制,如下所示:
1.主界面,代码如下所示:
<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"    xmlns:s="library://ns.adobe.com/flex/spark"    xmlns:mx="library://ns.adobe.com/flex/mx"   initialize="windowedapplication1_initializeHandler(event)"   showStatusBar="false"    width="50"     height="60"      ><fx:Style source="css/style.css" /><fx:Declarations><!-- 将非可视元素(例如服务、值对象)放在此处 --><mx:Glow id="Glow1"  alphaFrom="0" alphaTo="1" blurXFrom="1"   blurXTo="100" blurYFrom="1" blurYTo="100" duration="5000"      inner="true" target="{displayImg}" /> </fx:Declarations><fx:Script><![CDATA[import com.floor.screen.redevelop.app.window.myWin;import flash.display.NativeWindow;import mx.controls.Alert;import mx.events.FlexEvent; //动态绑定[Bindable][Embed(source='assets/image004.png')]public var icons:Class;//定时器初始化public var glowTimer:Timer=new Timer(5000); /** * 功能点: * 初始化加载函数 * 去掉最大化,最小化,关闭按钮,还有状态栏 * 并实现置顶,浮动,可拖拽的效果 **/ protected function windowedapplication1_initializeHandler(event:FlexEvent):void{                      displayImg.source = icons;  //绑定定时器事件,启动定时器  glowTimer.addEventListener(TimerEvent.TIMER,GlowTimerFunc);   glowTimer.start(); }/** * 定时器响应函数 **/ public function GlowTimerFunc(event:TimerEvent):void{      Glow1.play(); } /** * 拖拽,置顶效果 */ public function mouseDown(event:MouseEvent):void{  this.stage.nativeWindow.startMove(); this.stage.nativeWindow.alwaysInFront=true; } /** * 图片点击事件 **/ protected function displayImg_clickHandler(event:MouseEvent):void{  // Alert.show("hello world");var mw:myWin = new myWin();mw.advOpen(this);mw.move(50,50);//防止父窗口打开过多当前窗口,因而将其隐藏this.visible = false;//if(mw.parentWindow.hasOwnProperty("close")){//mw.parentWindow.close(); ////调用父窗口的close方法//}}public function open(event:Event):void{this.open(event);}]]></fx:Script><s:Image id="displayImg"  x="6" y="7" width="100%" height="100%"    mouseDown="mouseDown(event)"         click="displayImg_clickHandler(event)"        /></s:WindowedApplication>
2.myWin.as类,代码如下:
package com.floor.screen.redevelop.app.window{import flash.display.NativeWindowSystemChrome;import flash.display.Screen;import flash.events.Event;import flash.events.MouseEvent;import flash.geom.Rectangle;import mx.core.Container;import mx.core.ScrollPolicy;import mx.core.Window;import mx.core.WindowedApplication;public class myWin extends Window{//类窗口类public var parentWindow:Object;//自定义组件类public var subGroup:myGroup;public function myWin(){this.showStatusBar  =  false; //不显示底部状态栏this.showGripper = false;   //不显示底部大小控制按钮this.alwaysInFront = true;  //置顶操作this.minimizable =  false;this.transparent = true;this.width = 200 ;  //宽度this.height =100;  //高度this.maximizable = false ;  //不可最大化//去除窗口的边框、菜单栏this.systemChrome="none" ;this.resizable  = false ;this.showTitleBar = false ;//this.systemChrome  =  NativeWindowSystemChrome.NONE; //不显示系统窗口    //窗体永不出现垂直和水平滚动条this.horizontalScrollPolicy = ScrollPolicy.OFF;this.verticalScrollPolicy=ScrollPolicy.OFF; //显示位置var mainScreen:Screen = Screen.mainScreen;var screenBounds:Rectangle =  mainScreen.bounds;this.bounds=new Rectangle(300, 0,400, 400);//窗口在(600,300)处,宽为300,高为300;//this.bounds=screenBounds//窗口为屏幕大小;//添加窗体关闭事件注册   this.addEventListener(Event.CLOSE, exitEventHandler);//super();      //添加一个子控件,用来装载一些控件和图标   subGroup = new myGroup();   subGroup.width =  this.width- 2;   subGroup.height = this.height - 1;   this.addChild(subGroup);      subGroup.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);}/** * 自定义open()打开窗口并且保存调用此方法的对象 */public function advOpen(parentWindow:Object,openWindowActive:Boolean = true):void{this.parentWindow = parentWindow;this.open(true);}/** * 关闭事件响应函数 **/public function exitEventHandler(event:Event):void{    //显示上一级窗口this.parentWindow.visible = true;// cannot convert flash.events::Event@5d41da9 to flash.events.MouseEvent.//if(this.parentWindow.hasOwnProperty("open")){//this.parentWindow.open(event); ////调用父窗口的open方法//}}/** * 鼠标拖曳事件 **/public function mouseMoveHandler(event:MouseEvent):void{this.stage.nativeWindow.startMove(); this.stage.nativeWindow.alwaysInFront=true; }}}


3.myGroup.as类,代码如下:
package com.floor.screen.redevelop.app.window{import flash.desktop.NativeApplication;import flash.events.MouseEvent;import mx.containers.VBox;import mx.controls.Alert;import mx.controls.Button;import spark.components.Group;import spark.components.Label;public class myGroup extends Group{//添加下一级组件,比较图片文字按钮public var exitBtn:Button;public var testBtn:Button;public var vBox:VBox;/** * 在构造函数中初始化操作 **/ public function myGroup(){vBox = new VBox();//共用事件响应函数exitBtn = new Button();exitBtn.label = "退出程序" ;exitBtn.id = "exitBtn";exitBtn.addEventListener(MouseEvent.CLICK,addExitHandler);testBtn = new Button();testBtn.label = "测试功能" ;testBtn.id = "testBtn";testBtn.addEventListener(MouseEvent.CLICK,addExitHandler);   //添加至该容器中vBox.addElement(exitBtn);vBox.addElement(testBtn);this.addElement(vBox);//使用addElement,不能使用addChild,否则会报错}/** * 关闭按钮事件响应函数 **/ public function addExitHandler(event:MouseEvent):void{//得到其标识符var markFlagId:String = event.currentTarget.id;if(markFlagId == "testBtn"){//Alert.show("hello world");}else if(markFlagId  == "exitBtn"){//退出程序代码NativeApplication.nativeApplication.icon.bitmaps = [];NativeApplication.nativeApplication.exit();}}}}

实现效果如下所示:
	
				
		
原创粉丝点击