Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Flex 4.5 View Stack

Posted on 2011-10-04
3
Medium Priority
?
1,319 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:Tomboy77
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
dgofman earned 2000 total points
ID: 36918641
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
 
LVL 29

Expert Comment

by:dgofman
ID: 36918654
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
 

Author Closing Comment

by:Tomboy77
ID: 36928855
Appreciate it.
it's all set
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Ready to kick start your career in 2018? Add app developer skills to your resume. January’s Course of the Month features Android App Development training with hands-on learning.  Read on to learn why these skills are important.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question