`
msyspacer
  • 浏览: 9676 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Flex4 state状态设置

阅读更多

下面是一组最简单的状态

 

<?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" 
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   creationComplete="init()">
	<fx:Declarations>
		<!-- 非ビジュアルエレメント (サービス、値オブジェクトなど) をここに配置 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			protected function init():void
			{
				currentState = 'style1';
				st1.addEventListener(MouseEvent.CLICK,st1_cicked);
				st2.addEventListener(MouseEvent.CLICK,st2_cicked);
			}
			// 脚本控制切换
			protected function st1_cicked(event:Event):void
			{
				currentState = 'style1';
			}
			
			protected function st2_cicked(event:Event):void
			{
				currentState = 'style2';
			}
		]]>
	</fx:Script>
	<!--添加了2个state-->
	<s:states>
		<s:State name="style1"/>
		<s:State name="style2"/>
	</s:states>
	<s:Panel title="Mix" horizontalCenter="0" verticalCenter="0" width="450" height="300">
		<s:VGroup verticalCenter="0" horizontalCenter="0">
			<s:HGroup>
				<s:Button label="Style1" id="st1"/>
				<s:Button label="Style2" id="st2"/>
			</s:HGroup>
			<!--设置了2种状态下的属性-->
			<s:Label text="I just want to show this!" visible.style1="false" visible.style2="true" fontWeight="bold" fontSize="15"/>
		</s:VGroup>
	</s:Panel>
</s:Application>

 使用stateGroup的state

<?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" 
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   creationComplete="init()">
	<fx:Declarations>
		<!-- 非ビジュアルエレメント (サービス、値オブジェクトなど) をここに配置 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			protected function init():void
			{
				currentState = 'style1_1';
				st1.addEventListener(MouseEvent.CLICK,st1_cicked);
				st2.addEventListener(MouseEvent.CLICK,st2_cicked);
			}
			// 脚本控制切换
			protected function st1_cicked(event:Event):void
			{
				if(currentState == 'style1_1' || currentState == 'style1_2')
					currentState = 'style2_1';
				else  if(currentState == 'style2_1' || currentState == 'style2_2' )
						currentState = 'style1_1';
			}
			
			protected function st2_cicked(event:Event):void
			{
				if(currentState == 'style1_1' || currentState == 'style1_2')
					currentState = 'style2_2';
				else if(currentState == 'style2_1' || currentState == 'style2_2' )
					currentState = 'style1_2';
			}
			
			protected function st3_cicked(event:Event):void
			{
				currentState = 'style1_1';
			}
		]]>
	</fx:Script>
	<!--添加了4个state,2个stateGroup。stateGroup设置的属性是该组下state的公共属性。-->
	<s:states>
		<s:State name="style1_1" stateGroups="style1"/>
		<s:State name="style1_2" stateGroups="style1"/>
		<s:State name="style2_1" stateGroups="style2"/>
		<s:State name="style2_2" stateGroups="style2"/>
	</s:states>
	<s:Panel title="Mix" horizontalCenter="0" verticalCenter="0">
		<s:VGroup verticalCenter="0" horizontalCenter="0">
			<s:HGroup>
				<s:Button label.style1_1="Style1_1_A" label.style1_2="Style1_2_A" label.style2_1="Style2_1_A" label.style2_2="Style2_2_A" color.style1="#000000" color.style2="#C08888" id="st1"/>
				<s:Button label.style1_1="Style1_1_B" label.style1_2="Style1_2_B" label.style2_1="Style2_1_B" label.style2_2="Style2_2_B" color.style1="#000000" color.style2="#C08888" id="st2"/>
			</s:HGroup>
			<!--该button显示在style2中-->
			<s:Button label="Style2!" includeIn="style2" />
			<!--该组件显示在除了style1_1的所有状态中-->
			<s:Button label="Style1!" excludeFrom="style1_1"/>
		</s:VGroup>
	</s:Panel>
</s:Application>
 综合小程序

<?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" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   creationComplete="init()" xmlns:views="views.*">
	<s:layout>
		<s:VerticalLayout paddingLeft="20" paddingTop="20"/>
	</s:layout>
	<s:states>
		<s:State name="login" stateGroups="loggedOut"/>
		<s:State name="computers" stateGroups="loggedIn"/>
		<s:State name="info" stateGroups="loggedIn"/>
		<s:State name="tv" stateGroups="loggedIn"/>
	</s:states>
	<fx:Declarations>
		<!-- 非ビジュアルエレメント (サービス、値オブジェクトなど) をここに配置 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			
			protected function init():void
			{
				
			}
		]]>
	</fx:Script>
	<!--创建登陆界面-->
	<s:Panel includeIn="loggedOut" title.login="Get in there!">
		<s:layout>
			<s:VerticalLayout/>
		</s:layout>
		<s:Form>
			<s:FormItem label="用户名">
				<s:TextInput id="username"/>
			</s:FormItem>
			<s:FormItem label="密   码">
				<s:TextInput id="password"/>
			</s:FormItem>
		</s:Form>
		<mx:ControlBar>
			<s:Button label="Login" id="login" click="currentState='computers'"/>
		</mx:ControlBar>
	</s:Panel>
	<!--创建登陆后显示-->
	<s:HGroup includeIn="loggedIn">
		<s:ButtonBar dataProvider="{contentStack}"/>
		<s:Button label="log out" color="black" id="logout" click="currentState='login'"/>
	</s:HGroup>
	<mx:ViewStack id="contentStack" includeIn="loggedIn">
		<views:TVView label="TV"/>
		<views:ComputerView label="Com"/>
	</mx:ViewStack>
</s:Application>
 
分享到:
评论

相关推荐

    Flex tree+checkbox可实现级联勾选 修改

    先看评论再下,不要那么无聊,要不就不要下 flex tree+checkbox可实现级联勾选 修改后 修改CheckTreeDemoRenderer.as这个文件中 while (!...STATE_CHECKED 状态设置成true,其他的状态如果不用全设置false

    flex-最简单的state对象控制

    flex-最简单的state对象控制,可以实现相互切换,两种状态转换。

    Flex与ActionScript3程序开发

    第7章 特效effect和状态state 第8章 Flex与Flash无缝衔接 第9章 综合演练:实现仿Office 2007风格的界面 第3篇 组件高效技法篇 第10章 PopUpManager与ToolTipManager 第11章 Form组件与基本表单元素 第12章 ...

    Flex与ActionScript程序开发

    目录: Flex基础篇 1.走进Flex世界 ...特效effect和状态state 3.Flex与Flash无缝衔接 4.综合演练 组件高级技法篇 主要介绍各种常用组件的详细用法 性能优化篇 Flex通信篇 与js通信 与php通信 与j2ee通信

    flex3的cookbook书籍完整版dpf(包含目录)

    在FlexBuilder中设置MXML编译器选项 1.5节.在FlexBuilder外部编译Flex项目 1.6节.在MXML中添加事件监听器 1.7节.设置子节点属性 1.8节.定义数组和对象 1.9节.在ActionScript中设置变量的作用域 1.10节.在...

    有关单片机电子密码锁

    将程序下载到FLEX10K芯片中,同时在杭州康芯生产的型号为GW48-GK的EDA实验箱上进行硬件验证。经实验验证,该密码锁达到了设计要求。 本文提出的智能密码锁由于采用VHDL 语言设计,用一片FPGA实现,因而体积小...

    最新版vue前端面试题20230321整理

    15. 多个组件之间如何拆分各⾃自的state,每块⼩小的组件有⾃自⼰己的状态,它们 之间还有⼀一些公共的状态需要维护,如何思考这块 16. 使⽤用过的Redux中间件 17. 如何解决跨域的问题 18. 常⻅见Http请求头 19. ...

    css入门笔记

    4.伪类选择器 作用:匹配元素不同状态的选择器 语法:所有的伪类都是以 : 作为开始 选择器:伪类选择器{样式} 伪类分类 1.伪类链接 :link 匹配尚未访问的超级链接状态 :visited 匹配访问过的元素的状态 2....

    iOS应用内调试工具

    在调用FLEX时,应用窗口会显示一个工具栏,而在这个工具栏中,开发者可以对正在运行中的App的每一处状态进行查看或修改。 主要特性如下: 在层级中检查和修改视图; 可查看任意对象的属性和变量,并支持动态调整...

    Flutter-learn

    颤振学习有状态的班级模板import 'package:flutter/material.dart';class AudioPlayerTest extends StatefulWidget{ @override State&lt;StatefulWidget&gt; createState() { return _AudioPlayerTest(); }}class _...

    asp.net知识库

    ASP.NET: State Server Gems 完整的动态加载/卸载程序集的解决方案 从NUnit中理解.NET自定义属性的应用(转载) 如何在.NET中实现脚本引擎 (CodeDom篇) .NET的插件机制的简单实现 我对J2EE和.NET的一点理解 难分难舍...

Global site tag (gtag.js) - Google Analytics