zoukankan      html  css  js  c++  java
  • flex 让一个容器在另一个容器的内部移动,不会超界

    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"
    creationComplete="creationCompleteHandler()">

    <fx:Script>
       <![CDATA[
        import flash.geom.Rectangle;
        import mx.core.FlexGlobals;
        import mx.core.UIComponent;
        import mx.events.MoveEvent;
        import mx.managers.PopUpManager;
        import spark.components.TitleWindow;
       
        protected function creationCompleteHandler():void
        {
         var window:TitleWindow = new TitleWindow();
         PopUpManager.addPopUp(window, this, false);
         PopUpManager.centerPopUp(window);
         window.addEventListener(MoveEvent.MOVE, window_moveHandler);
        }
       
        protected function window_moveHandler(event:MoveEvent):void
        {
         var window:UIComponent = event.currentTarget as UIComponent;
         var application:UIComponent = FlexGlobals.topLevelApplication as UIComponent;
         var bounds:Rectangle = new Rectangle(0, 0, application.width, application.height);
         var windowBounds:Rectangle = window.getBounds(application);
         var x:Number;
         var y:Number;
         if (windowBounds.left <= bounds.left)
          x = bounds.left;
         else if (windowBounds.right >= bounds.right)
          x = bounds.right - window.width;
         else
          x = window.x;
         if (windowBounds.top <= bounds.top)
          y = bounds.top;
         else if (windowBounds.bottom >= bounds.bottom)
          y = bounds.bottom - window.height;
         else
          y = window.y;
         window.move(x, y);
        }
       
       ]]>
    </fx:Script>

    </s:WindowedApplication>

  • 相关阅读:
    【python3之文件操作】
    【Python3之字符编码】
    【python3之变量,输入输出,判断,循环】
    【Python3之正则re】
    【Python3的命名空间与作用域,闭包函数,装饰器】
    【Python3的函数初识】
    【Python3的进制扫盲】
    JS实现数组去重方法总结(六种方法)
    localstorage sessionstorage和cookie的区别,以及他们各自的用法总结
    es6 javascript对象方法Object.assign()
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100554.html
Copyright © 2011-2022 走看看