让程序在靠到屏幕边缘的时候,向左或者右收起程序,类似QQ一样
bbs.airia.cn/forum.php?mod=viewthread&tid=43346&page=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" width="900" height="650" creationComplete="windowedapplication1_creationCompleteHandler(event)"> <fx:Script> <!--[CDATA[ import com.greensock.TweenLite; import mx.core.FlexGlobals; import mx.events.FlexEvent; protected function button1_clickHandler(event:MouseEvent):void { this.width = 600; this.height = 500; } protected function button2_clickHandler(event:MouseEvent):void { this.width = 900; this.height = 650; } private var adsorption:String = 'null';//吸附的轴 private var AppWidth:Number; private function overHander(e:MouseEvent):void//鼠标触摸 { //当前应用程序在屏幕的位置 var x1:Number = FlexGlobals.topLevelApplication.stage.nativeWindow.x; var y1:Number = FlexGlobals.topLevelApplication.stage.nativeWindow.y; if(adsorption == 'x')//已经吸附<沿X轴> { if(x1 < 0)//已在屏幕左边吸附 { TweenLite.to(FlexGlobals.topLevelApplication.stage.nativeWindow,0.4,{x:-1});//从屏幕左侧滑出 } else if(x1+ this.width> AppWidth)//已在屏幕右边吸附 { TweenLite.to(FlexGlobals.topLevelApplication.stage.nativeWindow,0.4,{x:AppWidth-this.width+1});//从屏幕右侧滑出 } } if(adsorption == 'y')//已经吸附<沿Y轴> { if(y1 < 0)//已在屏幕上边吸附 { TweenLite.to(FlexGlobals.topLevelApplication.stage.nativeWindow,0.4,{y:-1});//从屏幕上边滑出 } } } private function outHander(e:MouseEvent):void//鼠标移出 { var x1:Number = FlexGlobals.topLevelApplication.stage.nativeWindow.x; var y1:Number = FlexGlobals.topLevelApplication.stage.nativeWindow.y; adsorption = 'null'; if(x1 <= 0)//当前程序在屏幕左侧 { adsorption = 'x'; TweenLite.to(FlexGlobals.topLevelApplication.stage.nativeWindow,0.4,{x:-this.width+2}); } else if(x1+ this.width>= AppWidth)//当前程序在屏幕右侧 { adsorption = 'x'; TweenLite.to(FlexGlobals.topLevelApplication.stage.nativeWindow,0.4,{x:AppWidth-2}); } if(y1 <= 0 && adsorption == 'null')//当前程序在屏幕上边 { adsorption = 'y'; TweenLite.to(FlexGlobals.topLevelApplication.stage.nativeWindow,0.4,{y:-this.height+2}); } } protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void { //鼠标触摸了应用程序 this.addEventListener(MouseEvent.MOUSE_OVER,overHander); //鼠标移出了应用程序 this.addEventListener(MouseEvent.MOUSE_OUT,outHander); this.AppWidth = Capabilities.screenResolutionX; trace("this.AppWidth:"+this.AppWidth); } ]]--> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <s:Button x="100" y="15" label="按钮" click="button1_clickHandler(event)"/> <s:Button x="9" y="15" label="按钮" click="button2_clickHandler(event)"/> <mx:Image x="10" y="44" width="801" height="601" source="images/New-UI_main.png"/> </s:WindowedApplication>
ps.
http://www.liuzm.com/article/flex/100315.htm