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

时间:2010-07-08 17:37:47

标签: flex flex3

我正在尝试通过在Panel控件的右上角添加句柄来实现可折叠的TitleWindow弹出窗口。不幸的是,当绘制控件时,我添加为句柄的图像不会显示。我可以通过改变图像的来源来触发重绘,所以显然它在那里,但它以某种方式被隐藏。

有没有办法让用户看到此Image控件?

这是窗口的代码:

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 个答案:

答案 0 :(得分:3)

您需要在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);
    }   

答案 1 :(得分:0)

我的PNG没有出现在我们的应用中。每隔一段时间,我们所有的PNG都会消失。要测试您的代码是否遇到同样的问题,请尝试使用GIF或其他格式的测试图像。如果它有效,那么你遇到的问题我已经遇到了几十次。

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

  1. 解决方法。切换你的项目的SDK版本,并且由于一些奇怪的原因,修复了它
    • 因此,例如,我们使用SDK 3.6
    • 我右键单击项目,选择属性并转到Flex SDK部分
    • 从那里我切换到任何其他SDK版本(比如Flex 3.2)并选择确定
    • 这会触发自动构建(具有某种神秘的PNG固定能力)
    • 然后我返回项目属性并将其返回到我们的版本。
    • 8次中的8次恢复PNG图像
    • 即使我们使用Flex SDK 3.4和3.5
    • ,这也有效
  2. 修复。将您的PNG格式更改为PNG-24
    • 似乎根本问题与使用PNG-8格式有关
    • 对于我们的图像,我在Photoshop中打开原件按CMD-Shft-Ctrl-S,调用“Save For Web ...”
    • 然后我选择PNG-24作为格式,而不是PNG-8
    • 类似的过程应该适用于任何其他图像编辑程序
  3. 我希望在某种程度上有所帮助,

    - gMale

相关问题