0
我對Spark的Flex開發非常陌生,想澄清構建組件的最佳方法。數據綁定從皮膚到Flex中的視圖(Spark)
我以前曾試圖用綁定表達式來設置一個ViewStack的當前指數:
public class MyComponentView extends SkinnableComponent
{
public var selectedIndex:int = 0;
}
<s:Skin ...>
<mx:ViewStack selectedIndex="{hostComponent.selectedIndex}">
....
</mx:ViewStack>
</s:Skin ...>
但是,這種結合的表達似乎並不工作,儘管它,如果我表現出正確的數量將該綁定表達式移動到:Label。
爲了得到這個工作,所以我改變了代碼:
public class MyComponentView extends SkinnableComponent
{
[SkinPart(required = "true")]
public var myStack:ViewStack;
private var _selectedIndex:int = 0;
private var _indexChanged:Boolean;
public function set selectedHistoryIndex(value:int):void
{
_selectedIndex = value;
_indexChanged = true;
invalidateProperties();
}
override protected function partAdded(partName:String, instance:Object):void
{
super.partAdded(partName, instance);
switch (instance)
{
case myStack:
_indexChanged = true;
invalidateProperties();
break;
}
}
override protected function commitProperties():void
{
super.commitProperties();
if (_indexChanged && myStack)
{
_indexChanged = false;
myStack.selectedIndex = _selectedIndex;
}
}
}
<s:Skin ...>
<mx:ViewStack id="myStack">
....
</mx:ViewStack>
</s:Skin ...>
這是我意味着來做到這一點?
同意。我現在認爲它在第一種情況下不起作用的原因是計時問題 - selectedIndex在數據提供者之前被設置。 – ThisRestlessPilgrim