gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:50:23 25 4
gpt4 key购买 nike

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

有没有办法让这个 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);
}

}
}

最佳答案

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

关于apache-flex - 如何将控件添加到 flex 面板的标题栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3206367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com