加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex_控制弹出式窗口位置;

发布时间:2020-12-15 05:10:04 所属栏目:百科 来源:网络整理
导读:效果:通过单击窗口里边按钮可以使窗口移到相应位置; =WindowTitleCustom.mxml自定义组件 ?xml version="1.0" encoding="utf-8"? s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" ?? ??? ??? ??? xmlns:s="library://ns.adobe.com/flex/spark" ??

效果:通过单击窗口里边按钮可以使窗口移到相应位置;

=>WindowTitleCustom.mxml自定义组件

<?xml version="1.0" encoding="utf-8"?>

<s:TitleWindow 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="300" height="120" close="onCloseWind()">
?? ?
?? ?<fx:Script>
?? ??? ?<![CDATA[
?? ??? ??? ?import mx.managers.PopUpManager;
?? ??? ??? ?
?? ??? ??? ?/**
?? ??? ??? ? * 关闭窗口;
?? ??? ??? ? */
?? ??? ??? ?protected function onCloseWind():void{
?? ??? ??? ??? ?PopUpManager.removePopUp(this);
?? ??? ??? ?}
?? ??? ??? ?
?? ??? ??? ?/**
?? ??? ??? ? * 移动窗口;
?? ??? ??? ? */
?? ??? ??? ?protected function moveWindTo(location:String):void{
?? ??? ??? ??? ?// 属性声明;
?? ??? ??? ??? ?var newX:Number = 0;
?? ??? ??? ??? ?var newY:Number = 0;
?? ??? ??? ??? ?var padding:Number = 10;
?? ??? ??? ??? ?
?? ??? ??? ??? ?// 居中显示:
?? ??? ??? ??? ?if(location == "center"){
?? ??? ??? ??? ??? ?PopUpManager.centerPopUp(this);
?? ??? ??? ??? ??? ?return;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?if(location.indexOf("bottom") > -1) {
?? ??? ??? ??? ??? ?newY = (parent.height - this.height) - padding;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?if(location.indexOf("top") > -1) {
?? ??? ??? ??? ??? ?newY = padding;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?if(location.indexOf("left") > -1) {
?? ??? ??? ??? ??? ?newX = padding;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?if(location.indexOf("right") > -1) {
?? ??? ??? ??? ??? ?newX = (parent.width - this.width) - padding;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?move(newX,newY);
?? ??? ??? ?}
?? ??? ?]]>
?? ?</fx:Script>
?? ?
?? ?<fx:Declarations>
?? ??? ?<!-- 非可视元素 -->
?? ?</fx:Declarations>

?? ?<!--view-->
?? ?<s:VGroup horizontalCenter="0" verticalCenter="0" width="100%" height="100%">
?? ??? ?<s:HGroup width="100%">
?? ??? ??? ?<s:Button id="tlBtn" label="左上角" width="100%" click="moveWindTo('toplet')"/>
?? ??? ??? ?<s:Button id="trBtn" label="右上角" width="100%" click="moveWindTo('topright')"/>
?? ??? ?</s:HGroup>
?? ??? ?
?? ??? ?<s:VGroup width="100%" horizontalAlign="center">
?? ??? ??? ?<s:Button id="alignBtn" label="中间" click="moveWindTo('center')"/>
?? ??? ?</s:VGroup>
?? ??? ?
?? ??? ?<s:HGroup width="100%">
?? ??? ??? ?<s:Button id="blBtn" label="左下角" width="100%" click="moveWindTo('bottomleft')"/>
?? ??? ??? ?<s:Button id="brBtn" label="右下角" width="100%" click="moveWindTo('bottomright')"/>
?? ??? ?</s:HGroup>
?? ?</s:VGroup>
?? ?
</s:TitleWindow>


=>主应用程序

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ?? ??? ??? ??? xmlns:s="library://ns.adobe.com/flex/spark" ?? ??? ??? ??? xmlns:mx="library://ns.adobe.com/flex/mx" ?? ??? ??? ??? minWidth="1024" minHeight="768" pageTitle="TheStudioOfCenyebao" ?? ??? ??? ??? applicationComplete="initFn()"> ?? ? ?? ?<fx:Script> ?? ??? ?<![CDATA[ ?? ??? ??? ?import com.learn.Window.WindowTitleCustom; ?? ??? ??? ? ?? ??? ??? ?import mx.managers.PopUpManager; ?? ??? ??? ? ?? ??? ??? ?protected var customWin:WindowTitleCustom; ?? ??? ??? ?public function initFn():void{ ?? ??? ??? ??? ?trace("=>Welcome to The Studio Of Cenyebao."); ?? ??? ??? ??? ? ?? ??? ??? ??? ?// 实例化并打开窗口: ?? ??? ??? ??? ?customWin = new WindowTitleCustom(); ?? ??? ??? ??? ?PopUpManager.addPopUp(customWin,this,true); ?? ??? ??? ??? ?PopUpManager.centerPopUp(customWin); ?? ??? ??? ??? ? ?? ??? ??? ??? ?// 监听键盘:关闭窗口; ?? ??? ??? ??? ?stage.addEventListener(KeyboardEvent.KEY_UP,onKeyUpFn,false,true); ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?/** ?? ??? ??? ? * 使用Esc快捷键关闭窗口; ?? ??? ??? ? */ ?? ??? ??? ?protected function onKeyUpFn(event:KeyboardEvent):void{ ?? ??? ??? ??? ?if(event.keyCode == Keyboard.ESCAPE) { ?? ??? ??? ??? ??? ?PopUpManager.removePopUp(customWin); ?? ??? ??? ??? ??? ?trace("=>窗口已经关闭!"); ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?]]> ?? ?</fx:Script> ?? ? ?? ?<fx:Declarations> ?? ??? ?<!-- 非可视元素 --> ?? ?</fx:Declarations> ?? ? ?? ?<!--view--> </s:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读