header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Priyanka Kshirsagar
Points:0
Posts:0

8/4/2011 7:43:15 AM

Title: How to Come back to main application on click of Button which is in application's Component?


Please check the code and tell me How I will be back in main application on click of Logout Button which is in Navigation.mxml. Project.mxml is main application.

Project.mxml

<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" width="100%" height="100%" creationComplete="init()">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
		<mx:StringValidator source="{uname}" id="unameValid" property="text"/>
		<mx:StringValidator source="{password}" id="passwordValid" property="text"/>
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.events.ValidationResultEvent;
			import mx.validators.Validator;
			private var myValidators:Array = new Array;
			private var nav:Navigation;
			
			private function init():void{
				btnLogin.addEventListener(MouseEvent.CLICK,validateForm);
				myValidators = [unameValid,passwordValid];
			}
			
			private function validateForm(event:Event):void{
				//Alert.show("in validate form");
				var errors:Array = Validator.validateAll(myValidators);
				if(errors.length == 0){
					loginUser();
				}else{
					Alert.show("in else");
				}
			}
			
			private function loginUser():void{
				//Alert.show("In login Form");
				nav = new Navigation();
				this.addElement(nav);
			}
		]]>
	</fx:Script>
	<s:Label text="Login Form" fontWeight="bold" fontSize="16" horizontalCenter="-110" 
			 verticalAlign="middle" verticalCenter="-280"/>
	<mx:Form horizontalCenter="-120" verticalCenter="-200" fontWeight="bold" verticalGap="20">
		<mx:FormItem label="UserName">
			<s:TextInput id="uname" restrict="A-Z a-z" focusIn="uname.errorString = null" text="Priyanka"/>
		</mx:FormItem>
		<mx:FormItem label="Password">
			<s:TextInput id="password" displayAsPassword="true" focusIn="password.errorString = null" text="aamir#23"/>
		</mx:FormItem>
		<mx:FormItem>
			<mx:HBox horizontalGap="20">
				<s:Button label="Login" id="btnLogin" />
				<mx:LinkButton label="Register" id="register"/>
			</mx:HBox>
		</mx:FormItem>
	</mx:Form>
</s:Application>


Navigation.mxml


<mx:Panel xmlns:fx="http://ns.adobe.com/mxml/2009" 
		  xmlns:s="library://ns.adobe.com/flex/spark" 
		  xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="100%" height="100%" xmlns:local="*">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import spark.components.Application;
			private function logout(event:MouseEvent):void{
				
			}
		]]>
	</fx:Script>
	<s:TabBar id="tabs" left="10" y="5" dataProvider="{vs}"/>
	<mx:ViewStack id="vs" width="90%" height="90%" left="10" y="30">
		<s:NavigatorContent label="DashBoard" width="100%" height="100%">
			<s:BorderContainer width="100%" height="100%" borderWeight="2" cornerRadius="3" dropShadowVisible="true">
				<s:Label text="In DashBoard"/>
			</s:BorderContainer>
		</s:NavigatorContent>
		<s:NavigatorContent label="User Information" width="100%" height="100%">
			<s:BorderContainer width="100%" height="100%" borderWeight="2" cornerRadius="3" dropShadowVisible="true">
				<s:Label text="In UserInfo"/>
			</s:BorderContainer>
		</s:NavigatorContent>
	</mx:ViewStack>
	<s:Button x="494" y="1" label="Logout" id="btnLogout" click="logout(event);"/>
</mx:Panel>



1
Arvind
Points: 0
Posts:0
8/11/2011 3:00:03 AM



Hi,
I think viewStack is work for you. change the viewstack index on login and logout.


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 1+0 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions