代码之家  ›  专栏  ›  技术社区  ›  Dan Monego

如何将控件添加到flex面板的标题栏?

  •  2
  • Dan Monego  · 技术社区  · 16 年前

    有没有办法让这个图像控件对用户可见?

    package
    {
        import mx.containers.Panel;
        import mx.controls.Image;
    
        public class CollapsableWindow extends Panel
        {
            public function CollapsableWindow()
            {
                super();
            }
    
            public var close:Image;
    
            protected override function createChildren():void
            {
                super.createChildren();
                close = new Image();
                close.source = "/assets/close.png";
                close.x = this.width - 20;
                close.y = 8;
                this.titleBar.addChildAt(close, 0);
            } 
    
        }
    }
    
    2 回复  |  直到 16 年前
        1
  •  3
  •   Wade Mueller    16 年前

    您需要在createChildren方法中创建按钮,然后将其放置在updateDisplayList方法中:

        /**
         * Creates the button and adds it to the titlebar
         */
        override protected function createChildren():void 
        {
            super.createChildren();
    
            this.myButton = new Button();
            this.myButton.addEventListener(MouseEvent.CLICK, onButtonClick);
            this.titleBar.addChild(this.myButton);
        }
    
        /**
         * Sizes and positions the button on the titlebar
         */
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void 
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
    
            this.myButton.setActualSize(myButton.getExplicitOrMeasuredWidth(),
                                           myButton.getExplicitOrMeasuredHeight());
    
            // Position the button 
            var y:int = 4;
            var x:int = this.width - this.myButton.width - 2;
            this.myButton.move(x, y);
        }   
    
        2
  •  0
  •   gMale    16 年前

    在我们的项目中,我们通过两种方式解决这个问题:

    1. 变通办法 . 切换项目的SDK版本,出于某种奇怪的原因,这会修复它
      • 我右键单击项目,选择properties并转到flexsdk部分
      • 从那里我切换到任何其他SDK版本(比如Flex3.2)并选择ok
      • 这会触发一个自动构建(具有某种神秘的PNG修复能力)
      • 然后我返回到项目属性并将其返回到我们的版本。
      • 10次中有8次恢复PNG图像
      • 即使在我们使用flexsdk3.4和3.5的时候,这也能起作用
    2. 修补程序。 将PNG格式更改为PNG-24
      • 对于我们的图片,我在Photoshop中按CMD-Shft-Ctrl-S打开原稿,调用“保存为Web…”
      • 然后我选择PNG-24作为格式,而不是PNG-8
      • 类似的过程应该适用于任何其他图像编辑程序

    我希望这能有所帮助,

    推荐文章