换肤时访问 hostComponent 的自定义属性 - Flex 4.5、SDK 4.5
使用 SDK 4.1,我能够从自定义皮肤访问自定义按钮组件的自定义属性。我当前正在工作的项目需要 SDK 4.5,但我无法访问这些属性。下面是一个示例:
自定义按钮组件
<?xml version="1.0" encoding="utf-8"?>
<s:ButtonBase xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
skinClass="components.skins.ButtonIcon_Skin"
>
<fx:Declarations>
<fx:String id="iconCustom" />
</fx:Declarations>
</s:ButtonBase>
自定义按钮皮肤
<?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
minWidth="21" minHeight="21"
alpha.disabled="0.5">
<fx:Metadata>[HostComponent("components.ButtonIcon")]</fx:Metadata>
...
<s:Label id="test" {hostComponent.iconCustom}"
horizontalCenter="0" bottom="10" />
</s:SparkButtonSkin>
代码提示显示 hostComponent.iconCustom
但随后给出错误:
Access of possibly undefined property iconCustom through a reference with static type spark.components.supportClasses:ButtonBase. ButtonIcon_Skin.mxml
Using SDK 4.1 I was able to access custom properties of a custom button component from a custom skin. The project I'm currently working requires SDK 4.5 and I'm unable to to access the properties. Here's an example:
Custom Button Component
<?xml version="1.0" encoding="utf-8"?>
<s:ButtonBase xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
skinClass="components.skins.ButtonIcon_Skin"
>
<fx:Declarations>
<fx:String id="iconCustom" />
</fx:Declarations>
</s:ButtonBase>
Custom Button Skin
<?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
minWidth="21" minHeight="21"
alpha.disabled="0.5">
<fx:Metadata>[HostComponent("components.ButtonIcon")]</fx:Metadata>
...
<s:Label id="test" {hostComponent.iconCustom}"
horizontalCenter="0" bottom="10" />
</s:SparkButtonSkin>
The code hint shows hostComponent.iconCustom
but then gives the error :
Access of possibly undefined property iconCustom through a reference with static type spark.components.supportClasses:ButtonBase. ButtonIcon_Skin.mxml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将 SparkButtonSkin 替换为常规 Skin 即可:
Just replace that SparkButtonSkin with a regular Skin and you'll be just fine:
另一种选择是,如果您想使用 SparkButtonSkin,只需转换为实际的 hostComponent
或上下文中:
自定义按钮皮肤
Another option, if you want to use SparkButtonSkin, just cast to your actual hostComponent
or in context:
Custom Button Skin