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

被折叠的 条评论
为什么被折叠?



