currentState使用范例

本文介绍了一个使用Flash技术实现的面板状态切换案例。通过点击面板,可以改变其位置,从左侧移动到右侧,反之亦然。此外,还提供了一个返回按钮用于重置面板位置。

currentState的意思是页面当前的状态,可以通过这个方法来改变当前页面的状态,比如改变页面的样式等。

一下代码的作用是点击鼠标的时候,panel的位置发生改变。

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:Script>

 

<!-- 点击鼠标时panel改变的动作 -->
 <![CDATA[
  public function movePanel():void
  {
   if(currentState == "toLeft")
   {
    currentState = "toRight";
   }else{
    currentState = "toLeft";
   }
  }
 ]]>
</mx:Script>

 

<!-- 创建一个panel -->

 <mx:Panel id="tryCurrentState" width="300" height="200" x="0" y="0" click="movePanel()"/>

<!-- 创建一个返回按钮,用来返回初始状态-->

 <mx:Button label="Back" click="currentState=''"/>

<!-- 页面当前状态 -->
 <mx:states>

 <!-- 第一个状态,panel在页面的左边 -->
  <mx:State name="toLeft">

  <!-- 设置页面的样式,target:要设置的目标 ,name:要设置的样式名称,value:要设置的样式的值  -->
   <mx:SetStyle target="{tryCurrentState}" name="left" value="50"/>
  </mx:State>
  <mx:State name="toRight">
   <mx:SetStyle target="{tryCurrentState}" name="right" value="50"/>
  </mx:State>
 </mx:states>
</mx:Application>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

带头大哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值