Flex 移动皮肤覆盖父皮肤的 hostComponent?
问题很简单,我扩展 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你必须这样做? hostComponent 是一个 ButtonBase,它是您的 ImageButton 的扩展。为什么需要改变hostComponent的类型?如果您需要将 hostComponent 作为 ImageButton 访问,那么您可以将其转换:
在对此问题的评论中,您说:
这根本不应该是真的。您自己说过您的 hostComponent 具有 ButtonBase 类型,但您正在扩展 ButtonSkin。根据您的声明,您将无法在 Button 组件上使用 ButtonSkin,只能在 ButtonBase 组件上使用。那不是真的。
我还将对 @RIAstar 关于元数据的评论添加一项说明。元数据仅用于编译器的代码提示和 MXML 参数检查。您可以轻松创建无需其中任何一个的样式。您只需使用 setStyle 方法设置值:
您可以在皮肤中使用它,如下所示:
我认为(但不确定)您也可以通过 CSS 设置样式,即使未声明元数据。通过使用 Spark 组件生命周期,应该完全可以在组件初始化其样式之前设置样式。
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:
In the comments to this question, you said:
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:
And you can use it in the skin like this:
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.