回答這個問題還爲時過晚。實際上,我們可以使用Spark Skin爲View組件蒙皮,沒有任何問題。View只是SkinnableContainer的一個子類(它是SkinnableComponent的子類),所以默認情況下,直接添加到View組件的MXML的任何內容都將被添加到SkinnableContainer的contenGroup中。
我添加了一個例子使用的Spark皮膚對皮膚的觀點:
主要用途:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160">
<fx:Script>
<![CDATA[
import com.accessdigital.core.SimpleView;
]]>
</fx:Script>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace core "com.accessdigital.core.*";
core|SimpleView{
skinClass : ClassReference("skin.view.Skin_SimpleView");
}
</fx:Style>
<s:ViewNavigator width="100%" height="100%"
firstView="{SimpleView}">
</s:ViewNavigator>
</s:Application>
視圖類
public class SimpleView extends View
{
public function SimpleView()
{
super();
}
[SkinPart(required="true")]
public var myButton:Button;
override protected function createChildren():void{
super.createChildren();
var anotherButton:Button = new Button();
anotherButton.label = "Another button";
anotherButton.addEventListener(MouseEvent.CLICK, onAnotherButtonClick);
if(!actionContent){
actionContent = [];
}
actionContent.push(anotherButton);
}
protected function onAnotherButtonClick(event:MouseEvent):void
{
trace("This is another button");
}
override protected function partAdded(partName:String, instance:Object):void{
super.partAdded(partName, instance);
if(instance == myButton){
myButton.addEventListener(MouseEvent.CLICK, onButtonClick);
}
}
protected function onButtonClick(event:MouseEvent):void
{
trace("This is a simple button");
}
}
皮膚文件:
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<!-- host component -->
<fx:Metadata>
[HostComponent("com.accessdigital.core.SimpleView")]
</fx:Metadata>
<!-- states -->
<s:states>
<s:State name="disabled" />
<s:State name="normal" />
</s:states>
<!-- SkinParts
name=myButton, type=spark.components.Button, required=true
name=contentGroup, type=spark.components.Group, required=false
-->
<s:Rect width="100%" height="100%">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="#666666"/>
<s:GradientEntry color="#222222"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Group id="contentGroup" width="100%" height="100%">
<s:Button id="myButton" label="My Button" horizontalCenter="0" verticalCenter="0"/>
</s:Group>
</s:Skin>
希望它幫助