Flex移动皮肤覆盖主体皮肤的主体成分?

时间:2012-02-10 05:24:43

标签: flex flex4 skinning flex-mobile

?问题非常简单,我将Button扩展为创建ImageButton,并扩展ButtonSkin以创建ImageButtonSkin。但是,当我像这样定义hostComponent时:

public var hostComponent:ImageButton

我得到一个错误,即与ButtatonSkinBase中的hostComponent:ButtonBase发生冲突。

如何扩展皮肤并为其提供新的hostComponent?

1 个答案:

答案 0 :(得分:2)

  

如何扩展皮肤并为其提供新的hostComponent?

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

var myImageButton : ImageButton = hostComponent as ImageButton;

在对这个问题的评论中,你说:

  

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

这根本不应该是真的。你自己说过你的hostComponent有一种ButtonBase,但是你正在扩展ButtonSkin。根据您的声明,您将无法在Button组件上使用ButtonSkin,仅在ButtonBase组件上使用ButtonSkin。事实并非如此。

我还要对@ RIAstar关于元数据的评论添加一个澄清。元数据仅用于编译器的代码提示和MXML参数检查。您可以轻松创建一种没有任何一种风格的风格。您只需使用setStyle方法设置值:

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

你可以在皮肤上使用它:

this.getStyle('myImageColor');

我认为 - 但我不确定 - 即使未声明元数据,您也可以通过CSS设置样式。使用Spark Component lifeCycle,应该可以在组件初始化其样式之前设置样式。

相关问题