Flex 中的States(状态)
关键字: flex, states
States 是一套用于创建状态组件的强大工具,也就是说组件可以有多个视图。
使用States 来切换视图可以节约资源
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:states>
<mx:State name="Register">
<mx:AddChild relativeTo="{loginForm}" position="lastChild">
<mx:FormItem id="confirm" label="确认密码">
<mx:TextInput/>
</mx:FormItem>
</mx:AddChild>
<mx:SetProperty target="{loginPanel}" name="title" value="注册"/>
<mx:SetProperty target="{loginButton}" name="label" value="注册"/>
<mx:RemoveChild target="{registerLink}"/>
<mx:AddChild relativeTo="{spacerl}" position="before">
<mx:LinkButton label="返回到登陆" click="currentState=''"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Panel id="loginPanel" title="登陆" fontSize="12" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Form id="loginForm">
<mx:FormItem label="用户名:">
<mx:TextInput/>
</mx:FormItem>
<mx:FormItem label="密码:">
<mx:TextInput/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar>
<mx:LinkButton id="registerLink" label="还未注册?" click="currentState='Register'"/>
<mx:Spacer width="100%" id="spacerl"/>
<mx:Button label="登陆" id="loginButton"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
本文介绍如何使用Flex中的States特性来创建具有多种视图的状态组件,通过示例代码展示了如何实现登录与注册页面间的平滑切换,有效利用资源。
141

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



