【问题标题】:Flex 4, Set variable in component skin from componentFlex 4,从组件设置组件皮肤中的变量
【发布时间】:2011-11-07 20:41:37
【问题描述】:

给定一个基于 SkinnableContainer 的自定义组件,我如何在运行时在皮肤中设置值?具体来说,它是一个白板组件,其 maxWidth 和 maxHeight 值表示对话中所有白板的最小共享宽度/高度。

[Bindable]
public var maxWhiteBoardWidth:Number;
[Bindable]
public var maxWhiteBoardHeight:Number;

这些值用于在对话中使用皮肤中的笔划线在所有较大白板的表面上绘制指南:

<!-- smallest common denominator boundaries -->
<s:Line left="300" top="0" bottom="0">
    <s:stroke>
        <s:SolidColorStroke weight="1" color="0xFFFFFF" />
    </s:stroke>
</s:Line>

<s:Line top="300" left="0"  right="0">
    <s:stroke>
        <s:SolidColorStroke weight="1" color="0xFFFFFF" />
    </s:stroke>
</s:Line>

不应将s:Line 的top 和left 属性中的值300 硬编码到皮肤中。它们应该反映组件中 maxWhiteBoardWidth/maxWhiteBoardHeight 的变化值。

我正在使用 MXML 中的 skinClass 属性设置皮肤。我需要动态加载皮肤吗?如果是这样,生命周期中的时间/方式?

我最近刚开始使用 Flex 3,因此 Spark 蒙皮架构仍然有点模糊。谢谢。

【问题讨论】:

    标签: flex4 skin flex-spark


    【解决方案1】:

    试试:

    <s:Line left="{hostComponent.maxWhiteBoardWidth}" top="0" bottom="0">
      ...
    </s:Line>
    <s:Line top="{hostComponent.maxWhiteBoardHeight}" left="0"  right="0">
      ...
    </s:Line>
    

    并确保您拥有元数据指令:

    <fx:Metadata>
          <!-- Specify the component that uses this skin class. -->
          [HostComponent("my.component.MyComponent")]
    </fx:Metadata>
    

    否则您在组件上的自定义属性将无法正确地暴露给皮肤。

    【讨论】:

      猜你喜欢
      • 2011-04-01
      • 2011-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 2011-03-24
      • 2012-07-18
      相关资源
      最近更新 更多