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

Tomboy77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgofmanCommented:
The same way, but you have couple mistakes in your code

1) You are trying to get children by name under ViewStack but your views wrapped by NavigatorContent in this case assigne  id(s) to NavigatorContent

<mx:ViewStack id="vs">
            <s:NavigatorContent id="loginViewID">
                  <view:Login/>
            </s:NavigatorContent>
            <s:NavigatorContent id="adminViewID">
                  <view:AdminView/>
            </s:NavigatorContent>
      </mx:ViewStack>

2) You have to change cast from Container to NavigatorContent

var viewStack:ViewStack = FlexGlobals.topLevelApplication.vs as ViewStack ;
                              var content:NavigatorContent = viewStack.getChildByName(viewId) as NavigatorContent;
                              if (content != null)
                              {
                                    viewStack.selectedChild = content;
                              }


3) If you don't want to use NavigatorContent warpper extends your Login and AdminView from NavigatorContent

instead

<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%">

use

<s:NavigatorContent 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%">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgofmanCommented:
If you will use option 3 your ViewStack will be

<mx:ViewStack id="vs">
                  <view:Login id="loginViewID"/>
                  <view:AdminView id="adminViewID"/>
      </mx:ViewStack>
0
Tomboy77Author Commented:
Appreciate it.
it's all set
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.