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

发布于 2024-09-09 04:12:59 字数 754 浏览 4 评论 0原文

我正在尝试通过向面板控件的右上角添加句柄来实现可折叠的 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);
        } 

    }
}

I'm trying to implement a collapsible TitleWindow popup by adding a handle to the top right corner of a Panel control. Unfortunately, the image that I add as the handle doesn't show up when the control is drawn. I can trigger a redraw by changing the source of the image, so apparently it's there, but it's somehow hidden.

Is there a way to make this Image control visible to the user?

Here's the code for the window:

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);
        } 

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别低头,皇冠会掉 2024-09-16 04:12:59

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

You need to create your button in the createChildren method, then position it in the updateDisplayList method:

    /**
     * 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);
    }   
猫瑾少女 2024-09-16 04:12:59

我遇到了 PNG 未显示在我们的应用程序中的问题。每隔一段时间,我们所有的巴布亚新几内亚就会消失。要测试您的代码是否遇到同样的问题,请尝试使用 GIF 或其他格式的测试图像。如果它有效,那么您将遇到我已经遇到过数十次的相同问题。

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

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

我希望以某种方式有所帮助,

--gMale

I've had issues with PNG's not showing up in our app. Every once in a while, all our PNG's disappear. To test whether you're code suffers the same problem, try using a test image that's a GIF or other format. If it works then you're having the same issue I've run into dozens of times.

On our project, we solve this in two ways:

  1. A workaround. Toggle your project's SDK version and, for some odd reason, that fixes it
    • So, for example, we use SDK 3.6
    • I right click on the project, chose properties and go to the Flex SDK section
    • From there I switch to ANY OTHER SDK version (say Flex 3.2) and choose ok
    • This triggers an automatic build (with some kind of mysterious PNG-fixing power)
    • Then I go back into the project properties and return it to our version.
    • 8 times out of 10 this restores the PNG images
    • This worked even when we were using Flex SDK 3.4 and 3.5
  2. A fix. Change your PNG format to PNG-24
    • It seems the root problem is related to using the PNG-8 format
    • For our images, I open the original in Photoshop press CMD-Shft-Ctrl-S, invoking "Save For Web..."
    • Then I choose PNG-24 for the format, instead of PNG-8
    • A similar process should work in any other image editing program

I hope that helps in some way,

-- gMale

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文