在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
什么是Skinning?
步骤1:创建皮肤使用选项File > New > MXML Skin 创建MXML皮肤向导 输入包为 com.tutorialspoint.skin 的包,名称为 GradientBackgroundSkin ,并选择主机组件作为现有flex BorderContainer控件 spark.component.BorderContainer 。 现在你已经为BorderContainer创建了一个外观。 修改mxml皮肤文件 src / com.tutorialspoint / skin / GradientBackgroundSkin.mxml 的内容。 更新填充图层如下: <!-- fill --> <s:Rect id="backgroundRect" left="0" right="0" height="100%" top="0"> <s:fill> <s:LinearGradient rotation="90"> <s:GradientEntry color="0x888888" ratio="0.2"/> <s:GradientEntry color="0x111111" ratio="1"/> </s:LinearGradient> </s:fill> </s:Rect> 步骤2:涂抹皮肤您可以使用两种方式在组件上应用皮肤 在MXML脚本中应用皮肤(静态)使用 skinClass 属性将 GradientBackgroundSkin 应用于ID为 mainContainer 的BorderContainer。 <s:BorderContainer width="560" height="500" id="mainContainer" styleName="container"> <s:VGroup width="100%" height="100%" gap="50" horizontalAlign="center" verticalAlign="middle" skinClass="com.tutorialspoint.skin.GradientBackgroundSkin"> 在ActionScript中应用皮肤(动态)使用 skinClass 属性将 GradientBackgroundSkin 应用于ID为 mainContainer 的BorderContainer。 protected function gradientBackground_clickHandler(event:MouseEvent):void { mainContainer.setStyle("skinClass", GradientBackgroundSkin ); } Flex样式与皮肤示例让我们按照以下步骤在Flex应用程序中通过创建测试应用程序来查看操作中的换肤:
以下是 GradientBackgroundSkin.mxml 文件 src / com / tutorialspoint / skin / GradientBackgroundSkin.mxml 的内容。 <?xml version="1.0" encoding="utf-8"?> <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <!-- host component --> <fx:Metadata> [HostComponent("spark.components.BorderContainer")] </fx:Metadata> <!-- states --> <s:states> <s:State name="disabled" /> <s:State name="disabled" /> <s:State name="normal" /> </s:states> <!-- SkinParts name=contentGroup, type=spark.components.Group, required=false --> <!-- fill --> <s:Rect id="backgroundRect" left="0" right="0" height="100%" top="0"> <s:fill> <s:LinearGradient rotation="90"> <s:GradientEntry color="0x111111" ratio="0.2"/> <s:GradientEntry color="0x888888" ratio="1"/> </s:LinearGradient> </s:fill> </s:Rect> <!-- must specify this for the host component --> <s:Group id="contentGroup" left="0" right="0" top="0" bottom="0" /> </s:Skin> 以下是修改的 HelloWorld.mxml 文件 src / com / tutorialspoint / client / HelloWorld.mxml 的内容。 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" minWidth="500" minHeight="500" initialize="application_initializeHandler(event)"> <fx:Style source="/com/tutorialspoint/client/Style.css"/> <fx:Script> <![CDATA[ import com.tutorialspoint.skin.GradientBackgroundSkin; import mx.controls.Alert; import mx.events.FlexEvent; import spark.skins.spark.BorderContainerSkin; protected function btnClickMe_clickHandler(event:MouseEvent):void { Alert.show("Hello World!"); } protected function application_initializeHandler(event:FlexEvent):void { lblHeader.text = "My Hello World Application"; } protected function gradientBackground_clickHandler(event:MouseEvent):void { mainContainer.setStyle("skinClass", GradientBackgroundSkin ); } protected function standardBackground_clickHandler(event:MouseEvent):void { mainContainer.setStyle("skinClass", BorderContainerSkin ); } ]]> </fx:Script> <fx:Declarations> <s:RadioButtonGroup id="selectorGroup" /> </fx:Declarations> <s:BorderContainer width="500" height="500" id="mainContainer" skinClass="spark.skins.spark.BorderContainerSkin" horizontalCenter="0" verticalCenter="0" cornerRadius="10"> <s:VGroup width="100%" height="100%" gap="50" horizontalAlign="center" verticalAlign="middle"> <s:Label id="lblHeader" fontSize="40" color="green" styleName="heading"/> <s:Button label="Click Me!" id="btnClickMe" click="btnClickMe_clickHandler(event)"/> <s:RadioButton color="gray" fontWeight="bold" group="{selectorGroup}" label="Standard Background" click="standardBackground_clickHandler(event)" selected="true"/> <s:RadioButton color="gray" fontWeight="bold" group="{selectorGroup}" label="Gradient Background" click="gradientBackground_clickHandler(event)"/> </s:VGroup> </s:BorderContainer> </s:Application> 准备好所有更改后,让我们以正常模式编译和运行应用程序,就像在 Flex - 创建应用程序中一样 章节。 |
请发表评论