Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3234938
  • 博文数量: 530
  • 博客积分: 13360
  • 博客等级: 上将
  • 技术积分: 5473
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-13 13:32
文章分类

全部博文(530)

文章存档

2017年(1)

2015年(2)

2013年(24)

2012年(20)

2011年(97)

2010年(240)

2009年(117)

2008年(12)

2007年(8)

2006年(9)

分类: Web开发

2013-03-28 11:25:09

转载:http://blog.csdn.net/thinkinside/article/details/4635116
1.概述
    上一篇文章《FLEX皮肤实例2_自定义节点上添加skinstate》描述了如何定义皮肤,本章描述类如何与皮肤交互数据

2.在Skin中还可以引用Component中的数据
2.1 在Node中增加属性tokenCount

      变量_tokenCount用于在节点上显示数字
     

  1.         private var _tokenCount:int;
  2.         [Bindable("tokenChange")] //表示
  3.         public function get tokenCount():int
  4.         {
  5.             return _tokenCount;
  6.         }
  7.           
  8.         public function set tokenCount(value:int):void
  9.         {
  10.             _tokenCount = value;
  11.         }

2.2 在skin中指定HostComponent
      只有指定了hostcomponent,皮肤与类之间才能交互数据
     
       [HostComponent("skinsample.Node")]  
   
 

      皮肤使用类的属性例子如下
        

详细代码如下:

TransitionSkin.mxml


  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Skin xmlns:fx=""
  3.         xmlns:s="library://ns.adobe.com/flex/spark"
  4.         xmlns:mx="library://ns.adobe.com/flex/mx">
  5.     
  6.     <!-- host component -->
  7.     <fx:Metadata>
  8.         [HostComponent("nodeexam.Node")]
  9.     </fx:Metadata>
  10.     
  11.     <s:states>
  12.         <s:State name="normal" />
  13.         <s:State name="enable" />
  14.     </s:states>
  15.     
  16.     <s:Rect id="rect" radiusX="4" radiusY="4" top="0" right="0"
  17.             bottom="0" left="0">
  18.         <s:fill>
  19.             <s:SolidColor color="0x131313" color.enable="0xff0000" /><!--enable状态下为红色 -->
  20.         </s:fill>
  21.         <s:stroke>
  22.             <s:SolidColorStroke color="0x131313" weight="2" />
  23.         </s:stroke>
  24.     </s:Rect>
  25.     
  26.     <!-- text,normal状态下为白色,否则为蓝色 -->
  27.     <s:Label text="{hostComponent.tokenCount}" color="0x0000ff" color.normal="0xffffff"
  28.                  textAlign="center" verticalAlign="middle"
  29.                  horizontalCenter="0" verticalCenter="0"
  30.                  />
  31.     
  32.     <!--界面上不显示任何东西-->
  33.     <s:Button top="4" right="4" bottom="4" left="4" alpha="0" color="0x00ff00" includeIn="enable,normal"/>
  34.     
  35. </s:Skin>

3. 程序演示
主程序代码如下

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application
  3.     xmlns:fx=""
  4.     xmlns:s="library://ns.adobe.com/flex/spark"
  5.     xmlns:mx="library://ns.adobe.com/flex/halo"
  6.     xmlns:skinsample="nodeexam.*">
  7.         
  8.     <skinsample:Node skinClass="nodeexam.TransitionSkin" x="10" y="30" width="50" height="50" tokenCount="5"/>
  9.     <skinsample:Node skinClass="nodeexam.PlaceSkin" x="80" y="30" width="50" height="50"/>
  10.     
  11.     <skinsample:Node skinClass="nodeexam.TransitionSkin" x="150" y="30" width="50" height="50" isEnabled="true" tokenCount="2"/>
  12. </s:Application>

运行结果如下


阅读(2567) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~