Link to home
Start Free TrialLog in
Avatar of Tomboy77
Tomboy77Flag for United States of America

asked on

Flex 4.5 View Stack

Hello,

I have my View stack and in view stack I have two view Login view and AdminView.
Once Click on login burron in login view in Login.mxml it will open AdminView.mxml.

I know How to do in <mx:VBox> </mx:VBox> but using <S:Group>
I don't know.

var viewStack:ViewStack = FlexGlobals.topLevelApplication.vs as ViewStack ;
                              
                              var container:Container = Container(viewStack.getChildByName(viewId));
                                    
                              if (container != null)
                              {
                                    viewStack.selectedChild = container;
                              }
is working when I use Vbox instead of Sgroup.

Please let me know any solution.

Thank You
 
<?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" height="100%" width="100%" xmlns:view="com.us.view.*">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
	
	<mx:ViewStack id="vs">
		<s:NavigatorContent>
			<view:Login id="loginViewID"/>
		</s:NavigatorContent>
		<s:NavigatorContent id="adminID">
			<view:AdminView id="adminViewID"/>
		</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" 
		 xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import com.us.controller.ViewController;
			
			import mx.core.Container;
			import mx.containers.ViewStack;
			import mx.controls.Alert;
			import mx.controls.DataGrid;
			import mx.core.FlexGlobals;
			
			import spark.components.Application;
			
			public function checkLogin(event:Event,viewId:String):void{
				
				if((username.text=="admin") && ( password.text=="password")){
					
					trace("Loged")
					var viewStack:ViewStack = FlexGlobals.topLevelApplication.vs as ViewStack ;
					
					var container:Container = Container(viewStack.getChildByName(viewId));
						
					if (container != null)
					{
						viewStack.selectedChild = container;
					} 
					username.text = "";
					password.text = "";
				}
				
				else{
					
					Alert.show("Entered incorrect username or password");	
				}
			}
		]]>
	</fx:Script>
	<s:BorderContainer >
		
		<s:layout>
			<s:VerticalLayout horizontalAlign="center" verticalAlign="middle" />
		</s:layout>
		<s:Label text="Login" fontSize="15" fontWeight="bold" />
		<mx:Form  id="form" >
			
			<mx:FormItem label="User name:">
				<s:TextInput id="username"/>
			</mx:FormItem>
			<mx:FormItem label="Password:">
				<s:TextInput id="password" displayAsPassword="true"/>
			</mx:FormItem>
			<mx:FormItem>
				<s:Button id="button1" label="Log In" click="checkLogin(event,'adminViewID')"/>
			</mx:FormItem>
		</mx:Form>
	</s:BorderContainer >
</s:Group>

//Admin View

<?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" 
		height="100%" width="100%">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
	<s:Label text="Admin View"/>
</s:Group>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you will use option 3 your ViewStack will be

<mx:ViewStack id="vs">
                  <view:Login id="loginViewID"/>
                  <view:AdminView id="adminViewID"/>
      </mx:ViewStack>
Avatar of Tomboy77

ASKER

Appreciate it.
it's all set