air实现仿QQ提示窗口

 <?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml
      applicationComplete="initApplication()"
      layout="absolute"
      verticalAlign="top"
      horizontalAlign="left"
      width="250"
      height="200">
 <mx:Script>
  <![CDATA[
   import flash.net.*
    import flash.events.*
    import flash.display.*
    import mx.events.*
    import mx.controls.*
    import flash.system.*;
   import mx.core.*
    import flash.utils.Timer
    
    private var dockImage:BitmapData;  
   
   
   //初始化Application里调用此方法,完成上面的第一步:  
   
   public function initApplication():void{  
    
    var loader:Loader=new Loader();  
    
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,prepareForSystray);//这里就是完成第一步的任务须,这个prepareForSystray就是对托盘的生在和菜单的控制  
    
    loader.load(new URLRequest("a.jpg"));//这里先要加载托盘图标的小图片  
    
    this.addEventListener(Event.CLOSING,closingApplication);//设置关闭体的事件  
    
    this.horizontalScrollPolicy=ScrollPolicy.OFF
    this.verticalScrollPolicy=ScrollPolicy.OFF
   }  
   
   //生成托盘  
   
   public function prepareForSystray(event:Event):void{  
    
    dockImage=event.target.content.bitmapData;  
    
    if(NativeApplication.supportsSystemTrayIcon){  
     
     setSystemTrayProperties();//设置托盘菜单的事件  
     
     SystemTrayIcon(NativeApplication.nativeApplication.icon).menu=createSystrayRootMenu();//生成托盘菜单  
     
    }     
    
   }    
   
   //关闭窗体的事件  
   
   public function closingApplication(event:Event):void{  
    
    /*event.preventDefault();//阻止默认的事件  
    
    Alert.yesLabel="Close";  
    
    Alert.noLabel="Mini";  
    
    Alert.show("Close or Minimize?", "Close?", 3, this, alertCloseHandler);//弹出自定义的选择框, 关于Alert的详细用法,参考官方文档或我前面的相关文章.  
    */
   }  
   
   //根据用户的选择来判断做什么,这里选择是就是关闭,选择否(Mini)就是最小化到托盘.  
   
   private function alertCloseHandler(event:CloseEvent):void{  
    
    if(event.detail==Alert.YES){  
     
     closeApp(event);  
     
    }else{  
     
     dock();//最小化到托盘  
     
    }  
    
   }  
   
   public function createSystrayRootMenu():NativeMenu{  
    
    var menu:NativeMenu = new NativeMenu();  
    
    var openNativeMenuItem:NativeMenuItem = new NativeMenuItem("Open");//生成OPEN菜单项  
    
    var exitNativeMenuItem:NativeMenuItem = new NativeMenuItem("Exit");//同理  
    
    openNativeMenuItem.addEventListener(Event.SELECT, undock);  
    
    exitNativeMenuItem.addEventListener(Event.SELECT, closeApp);//添加EXIT菜单项事件  
    
    menu.addItem(openNativeMenuItem);  
    
    menu.addItem(new NativeMenuItem("",true));//separator   
    
    menu.addItem(exitNativeMenuItem);//将菜单项加入菜单  
    
    return menu;  
    
   }  
   
   //设置托盘图标的事件  
   
   private function setSystemTrayProperties():void{  
    
    SystemTrayIcon(NativeApplication.nativeApplication .icon).tooltip = "TurboSquid squidword";  
    
    SystemTrayIcon(NativeApplication.nativeApplication .icon).addEventListener(MouseEvent.CLICK, undock);  
    
    stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, nwMinimized);   
    
   }  
   
   //最小化窗体  
   private function nwMinimized(displayStateEvent:NativeWindowDisplayStateEvent):void {  
    
    if(displayStateEvent.afterDisplayState == NativeWindowDisplayState.MINIMIZED) {  
     
     displayStateEvent.preventDefault();//阻止系统默认的关闭窗体事件  
     
     dock();//将程序放入托盘  
     
    }  
    
   }  
   
   
   
   //将本地应用程序放到托盘  
   
   public function dock():void {  
    
    stage.nativeWindow.visible = false; //设置本地程序窗体不可见  
    
    NativeApplication.nativeApplication.icon.bitmaps = [dockImage];//设置托盘的图标  
    
    var mytimer:Timer=new Timer(60000, 0)
    mytimer.addEventListener(TimerEvent.TIMER,timerEvent)
    mytimer.start()
   }  
   
   function timerEvent(e:TimerEvent):void{
    
    undock(null)
    
   }
   
   //还原
   function goback(evt:Event):void{
    
    
    
    
    
   }
   
   //定时提醒
   public function undock(evt:Event):void {  
    
    //NativeApplication.nativeApplication.icon.bitmaps= [];//将托盘图标清空  
    
    this.addEventListener(Event.ENTER_FRAME,Event_ENTER_FRAME)
    
    stage.nativeWindow.width=200
    stage.nativeWindow.height=200
    
    stage.nativeWindow.x=Capabilities.screenResolutionX-stage.nativeWindow.width
    stage.nativeWindow.y=Capabilities.screenResolutionY-stage.nativeWindow.height
    
    myWindow=deChromeWindow(stage.nativeWindow)
    myWindow.visible=true
    
    pan.width= myWindow.width
    pan.height= myWindow.height
    
    pan.x=0
    pan.y=0
    
    pan.title="测试"
    
    pan.addEventListener(CloseEvent.CLOSE,CloseEvent_CLOSE)
    
    
    stage.nativeWindow.visible = true;//设置本地程序窗体可见  
    
    stage.nativeWindow.orderToFront();//设置本地程序窗体到最前端
    
    
   }  
   private function CloseEvent_CLOSE(e:CloseEvent):void{
    
    myWindow.visible=false
    
   }
   var myWindow:NativeWindow
   var num:Number=5
   var timeNum:Number=0
   
   private function Event_ENTER_FRAME(e:Event):void{
    
    //var myWindow:NativeWindow=stage.nativeWindow
    
    if(myWindow.y<Capabilities.screenResolutionY-myWindow.height-50){
     
     myWindow.y-=num
    }else{
     
     timeNum++
    }
    
    
    if(timeNum>100){
     
     myWindow.y-=-num
     
    }
    
    
    if(myWindow.y>Capabilities.screenResolutionY){
     
     timeNum=0
     CloseEvent_CLOSE(null)
     this.removeEventListener(Event.ENTER_FRAME,Event_ENTER_FRAME)
     
     
    }
    
    
    
   } 
   
   //关闭程序窗体  
   private function closeApp(evt:Event):void {  
    
    stage.nativeWindow.close();  
    
   } 
   
   //改变窗体样式    
   public function deChromeWindow(oldWindow:NativeWindow):NativeWindow{
    
    if(oldWindow.systemChrome != NativeWindowSystemChrome.NONE){
     var newOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
     newOptions.systemChrome = NativeWindowSystemChrome.NONE;
     newOptions.transparent = true;
     
     var newWindow:NativeWindow = new NativeWindow(newOptions);
     newWindow.stage.stageWidth = oldWindow.stage.stageWidth;
     newWindow.stage.stageHeight = oldWindow.stage.stageHeight;
     newWindow.stage.align = oldWindow.stage.align;
     newWindow.stage.scaleMode = oldWindow.stage.scaleMode;
     
     newWindow.x=oldWindow.x
     newWindow.y=oldWindow.y
     
     
     
     for(var i:int = 0; i < oldWindow.stage.numChildren; i++){
      newWindow.stage.addChild(oldWindow.stage.getChildAt(i));
     }
     newWindow.activate();
     oldWindow.close();
     
     return newWindow;
    }
    return oldWindow;
   }
   
  ]]>
 </mx:Script>
 <mx:TitleWindow x="0" y="0" width="250" height="200" layout="absolute" id="pan" showCloseButton="true">
 </mx:TitleWindow>
 
</mx:WindowedApplication>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值