hostComponent的剥皮时访问自定义属性 - 的Flex 4.5,SDK 4.5自定义、属性、hostComponent、SDK

2023-09-09 21:48:12 作者:宁缺☆勿滥

使用SDK 4.1,我能够从一个自定义皮肤访问自定义按钮组件的自定义属性。我目前工作的项目需要SDK 4.5,我无法访问属性。这里有一个例子:

自定义按钮组件

 < XML版本=1.0编码=UTF-8&GT?;
< S:ButtonBase的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
          XMLNS:S =库://ns.adobe.com/flex/spark
          的xmlns:MX =库://ns.adobe.com/flex/mx
          的skinClass =components.skins.ButtonIcon_Skin
          >
    < FX:声明>
        < FX:字符串ID =iconCustom/>
    < / FX:声明>
&所述; /秒:ButtonBase>
 

自定义按钮外观

 < XML版本=1.0编码=UTF-8&GT?;
< S:SparkButtonSkin的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
             XMLNS:S =库://ns.adobe.com/flex/spark
             的xmlns:FB =htt​​p://ns.adobe.com/flashbuilder/2009
             =了minWidth21=了minHeight21
             中用alpha.disabled =0.5>
    < FX:元数据> [HostComponent(components.ButtonIcon)< / FX:元数据>

...

    < S:标签ID =测试{hostComponent.iconCustom}
             horizo​​ntalCenter =0底部=10/>

&所述; /秒:SparkButtonSkin>
 
自定义解析IP实现快速访问指定网页

在code提示显示 hostComponent.iconCustom 但随后给出了错误:

 可能未定义的属性iconCustom通过与静态类型spark.components.supportClasses参考访问:ButtonBase。 ButtonIcon_Skin.mxml
 

解决方案

刚刚替换SparkButtonSkin一个普通的皮肤,你会就好了:

 < S:皮肤的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
        XMLNS:S =库://ns.adobe.com/flex/spark>

    < FX:元数据>
        [HostComponent(components.ButtonIcon)]
    < / FX:元数据>

    < S:国家>
        < S:国名=已禁用/>
        < S:国名=向下/>
        < S:国名=而不是/>
        < S:国名=向上/>
    < / S:国家>

    < S:标签文本=测试{hostComponent.iconCustom}
             horizo​​ntalCenter =0底部=10/>

< / S:皮肤>
 

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

解决方案

Just replace that SparkButtonSkin with a regular Skin and you'll be just fine:

<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark">

    <fx:Metadata>
        [HostComponent("components.ButtonIcon")]
    </fx:Metadata>

    <s:states>
        <s:State name="disabled" />
        <s:State name="down" />
        <s:State name="over" />
        <s:State name="up" />
    </s:states>

    <s:Label text="test {hostComponent.iconCustom}" 
             horizontalCenter="0" bottom="10" />

</s:Skin>