在flex4里使用state

设置state 的name属性的值 ,在其他组件利用里该name的值控制state .

 

state状态的改变时通过 currentState 属性来改变的。

 

 

<?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">
 
<s:states>
<s:State name="One"/>
<s:State name="Two"/>
<s:State name="Three"/>
</s:states>
 
<s:HGroup
horizontalCenter="0">
 
<s:Button
label="One"
click="this.currentState='One'"/>
 
<s:Button
label="Two"
click="this.currentState='Two'"/>
 
<s:Button
label="Three"
click="this.currentState='Three'"/>
 
</s:HGroup>
 
</s:Application>

 

 

上面的程序只是框架 ,现在我们来分析一下。 在flex3里,state的属性值只能在<s:state>里设置,但在flex4里, state的属性也可以再其他组件中设置 。如下面的  text.One  里的One  就是就是state的name属性的值.  后面的一个One 是输入的内容,可以任意设定 。

 

<s:Label
text.One = "One"
text.Two = "Two"
text.Three = "Three" />

下面是例子

<?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">
 
<s:states>
<s:State name="One"/>
<s:State name="Two"/>
<s:State name="Three"/>
</s:states>
 
<s:HGroup
horizontalCenter="0">
 
<s:Button
label="One"
click="this.currentState='One'"/>
 
<s:Button
label="Two"
click="this.currentState='Two'"/>
 
<s:Button
label="Three"
click="this.currentState='Three'"/>
 
</s:HGroup>
 
<s:Label
text.One = "One"
text.Two = "Two"
text.Three = "Three"
horizontalCenter="0"
top="50"
fontSize="40"
/>
 
</s:Application>

 

 

 

上面的程序在<s:Label> 里就用到state的name属性值

 

 

下面我们加入 面板panel:

 

 

 

 

<?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">
 
<s:states>
<s:State name="One"/>
<s:State name="Two"/>
<s:State name="Three"/>
</s:states>
 
<s:Panel
resizeEffect="Resize"
title.One="One"
title.Two="Two"
title.Three="Three"
width.One="800"
width.Two="200"
width.Three="400"
height.One="400"
height.Two="600"
height.Three="200"
horizontalCenter="0"
verticalCenter="0"
>
 
<s:Label
text.One="One"
text.Two="Two"
text.Three="Three"
horizontalCenter="0"
verticalCenter="0"
fontSize="40"
/>
 
</s:Panel>
 
<s:HGroup
horizontalCenter="0">
 
<s:Button
label="One"
enabled.One="false"
click="this.currentState='One'"/>
 
<s:Button
label="Two"
enabled.Two="false"
click="this.currentState='Two'"/>
 
<s:Button
label="Three"
enabled.Three="false"
click="this.currentState='Three'"/>
 
</s:HGroup>
 
</s:Application>

从<s:panel > 里可以看出(如:title.One="One") 我们可以用其他组件的属性加上点语法再加上state的name属性的值

(即:property.name'sValue="property相关的值") 来控制state .

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值