Flex 移动皮肤覆盖父皮肤的 hostComponent?

发布于 2025-01-04 05:25:18 字数 261 浏览 1 评论 0原文

问题很简单,我扩展 Button 来创建 ImageButton,我扩展 ButtonSkin 来创建 ImageButtonSkin。但是,当我像这样定义 hostComponent 时:

public var hostComponent:ImageButton

我收到一条错误,指出与 ButtonSkinBase 内的 hostComponent:ButtonBase 发生冲突。

如何扩展皮肤并为其提供新的主机组件?

?Problem is pretty simple, I extend Button to create ImageButton, and I extend ButtonSkin to create ImageButtonSkin. But, when I define hostComponent like this:

public var hostComponent:ImageButton

I get an error that there is a conflict with hostComponent:ButtonBase inside the ButttonSkinBase.

How do I extend a skin AND provide a new hostComponent for it?

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

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

发布评论

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

评论(1

梦醒灬来后我 2025-01-11 05:25:18

如何扩展皮肤并为其提供新的主机组件?

为什么你必须这样做? hostComponent 是一个 ButtonBase,它是您的 ImageButton 的扩展。为什么需要改变hostComponent的类型?如果您需要将 hostComponent 作为 ImageButton 访问,那么您可以将其转换:

var myImageButton : ImageButton = hostComponent as ImageButton;

在对此问题的评论中,您说:

所以,你可以延长皮肤,但你只能
将它用于父皮肤指定的组件,太棒了。

这根本不应该是真的。您自己说过您的 hostComponent 具有 ButtonBase 类型,但您正在扩展 ButtonSkin。根据您的声明,您将无法在 Button 组件上使用 ButtonSkin,只能在 ButtonBase 组件上使用。那不是真的。

我还将对 @RIAstar 关于元数据的评论添加一项说明。元数据仅用于编译器的代码提示和 MXML 参数检查。您可以轻松创建无需其中任何一个的样式。您只需使用 setStyle 方法设置值:

myHostComponent.setStyle('myImageColor',0x000000);

您可以在皮肤中使用它,如下所示:

this.getStyle('myImageColor');

我认为(但不确定)您也可以通过 CSS 设置样式,即使未声明元数据。通过使用 Spark 组件生命周期,应该完全可以在组件初始化其样式之前设置样式。

How do I extend a skin AND provide a new hostComponent for it?

Why do you have to? the hostComponent is a ButtonBase, which is something your ImageButton extends. Why do you need to change the type of the hostComponent? If you need to access the hostComponent as an ImageButton, then you can cast it:

var myImageButton : ImageButton = hostComponent as ImageButton;

In the comments to this question, you said:

So, you can extend the skin, but you can only
use it for the component that the parent skin specifies, amazing.

That shouldn't be true at all. You said yourself your hostComponent has a type of ButtonBase, but you are extending the ButtonSkin. By your statement, you would not be able to use the ButtonSkin on a Button component, only on ButtonBase component. That is not true.

I'll also add one clarification to @RIAstar's comment about metadata. Metadata is used only for code hinting and MXML parameter checking by the compiler. You can easily create a style w/o either of those. You'll just have to set the value using the setStyle method:

myHostComponent.setStyle('myImageColor',0x000000);

And you can use it in the skin like this:

this.getStyle('myImageColor');

I think--but am not sure--you can also set the style via CSS even though metadata is not declared. With use of the Spark Component lifeCycle, It should be perfectly possible to set a style before the component initializes its' styles.

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