如何扩展不是容器的 Flex 组件(例如 RadioButton)?

发布于 2024-07-28 22:45:42 字数 151 浏览 2 评论 0原文

我想扩展 Flex 3 中的 RadioButton 组件,向其添加文本输入行来代替标签。 是否有可能做到这一点?

或者,是否可以有一个容器(例如 HBox)将所有属性委托给内部组件(例如 RadioButton),以便我可以创建一个“类似于”单选按钮的复合组件?

I want to extend the RadioButton component in Flex 3, adding a text input line to it in place of the label. Is it possible to do this?

Alternately, is it possible to have a container -- such as an HBox -- delegate all properties to an internal component -- such as a RadioButton -- so that I could create a composite component that 'acts like' a radio button?

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

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

发布评论

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

评论(1

疾风者 2024-08-04 22:45:42

如果您在 Actionscript 类中扩展 RadioButton 类(而不是 mxml 文件 - 有更好的方法吗?),您应该能够添加文本输入,即:

package components
{
    import mx.controls.RadioButton;

    public class Test extends RadioButton
    {
        public function Test()
        {
            super();
        }

    }
}

您可能会发现这个 - http://www.adobe.com/devnet/flex/quickstart/building_components_in_as/ 的帮助,特别是标题为创建复合动作脚本组件的部分。 如果这是您的第一个自定义组件,您可能还需要阅读 Flex 组件生命周期 (http://weblog.mrinalwadhwa.com/2009/02/17/understanding-the-flex-component-lifecycle/ - 虽然我永远找不到好的那个东西的链接)。 Flex 组件的生命周期有点复杂,您需要确保自己理解它,这样您的组件就不会不必要地不断地重绘事物。

您需要在创建子函数中添加 textInput,textField 本身是在 Button(RadioButton 的子类)的 createChildren() 方法中创建的。

/**
 *  @private
 */
override protected function createChildren():void
{
    super.createChildren();

    // Create a UITextField to display the label.
    if (!textField)
    {
        textField = IUITextField(createInFontContext(UITextField));
        textField.styleName = this;
        addChild(DisplayObject(textField));
    }

}

If you extend the RadioButton class in an Actionscript class, (rather than an mxml file - is there a better way of saying that?), you should be able to add a text input, ie:

package components
{
    import mx.controls.RadioButton;

    public class Test extends RadioButton
    {
        public function Test()
        {
            super();
        }

    }
}

You might find this - http://www.adobe.com/devnet/flex/quickstart/building_components_in_as/ of help, particularly the section titled creating composite actionscript components. If this is your first custom component, you'll also probably want to read up on the Flex Component Lifecycle (http://weblog.mrinalwadhwa.com/2009/02/17/understanding-the-flex-component-lifecycle/ - although i can never find a good link for that stuff). The flex component lifecycle is a bit complex and you'll want to make sure you understand it so your component isn't needlessly redrawing things constantly.

You'll want to add the textInput in the create children function, the textField itself is created in Button's (which RadioButton subclasses) createChildren() method.

/**
 *  @private
 */
override protected function createChildren():void
{
    super.createChildren();

    // Create a UITextField to display the label.
    if (!textField)
    {
        textField = IUITextField(createInFontContext(UITextField));
        textField.styleName = this;
        addChild(DisplayObject(textField));
    }

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