flex4的viewstack之间的跳转

我的文件目录结构



我的chatroom.mxml

<?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" minWidth="955" minHeight="600"
			   xmlns:hearain="hearain.*">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[

		]]>
	</fx:Script>
	<mx:ViewStack id="room">
		<s:NavigatorContent>
			<hearain:login id="login">
			</hearain:login>	
		</s:NavigatorContent>
		<s:NavigatorContent>
			<hearain:welcome id="welcome" width="300" height="200">
			</hearain:welcome>
		</s:NavigatorContent>
	</mx:ViewStack>
</s:Application>

我的login.mxml组件

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
		 xmlns:s="library://ns.adobe.com/flex/spark"
		 creationComplete="group1_creationCompleteHandler(event)"
		 xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.containers.ViewStack;
			import mx.core.FlexGlobals;
			import mx.events.FlexEvent;
			private var vs:ViewStack;     //vs是main.mxml中定义的viewstack
			
			protected function group1_creationCompleteHandler(event:FlexEvent):void
			{
				// TODO Auto-generated method stub
				if(FlexGlobals.topLevelApplication is chatroom){
					if(FlexGlobals.topLevelApplication.room is ViewStack){
						vs = FlexGlobals.topLevelApplication.room as ViewStack;
					}
				}
			}
//			private function getChild(str:String):Object  //这段代码是为了获得指定页面对应的对象
//			{
//				for each(var obj:Object in vs.getChildren())  //遍历vs中的所有子组件(即所有页面),页面不会太多,顶多一二十个,所以这个方法不会太耗时
//				{
//					if(obj.name === str) //如果是想找的页面,就返回这个对象。比如想找到welcome.mxml,则令str="welcome"
//					{
//						break;
//					}
//				}
//				return obj;
//			}
			
			protected function button1_clickHandler(event:MouseEvent):void
			{
				// TODO Auto-generated method stub
				vs.selectedIndex = 1;//跳转至welcomeu页面
			}
			
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Button x="200" y="121" label="登录" click="button1_clickHandler(event)" />
</s:Group>

我的welcome.mxml组件

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
		 xmlns:s="library://ns.adobe.com/flex/spark" 
		 xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Label id="w" text="欢迎窗口" />
</s:Group>

我的运行结果:


点击登陆后跳转至welcome页面



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值