2011-11-07 36 views
0

给定一个基于SkinnableContainer的自定义组件,如何在运行时在皮肤中设置值?具体而言,它是一个带有maxWidth和maxHeight值的白板组件,用于指示会话中所有白板的最小共享宽度/高度。Flex 4,在组件皮肤中设置变量

[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> 

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

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

我最近来自Flex 3,因此Spark皮肤架构仍然有点模糊。谢谢。

回答

0

尝试:

<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> 

否则组件上的自定义属性将不能正确接触到皮肤。