Flex : Two State Login Panel (Component)

  • I used Flash Builder 4.5
  • Create a Flex Project
    (I created MyApp)
  • Create a package for components
  • Create an MXML components inside that package
    1. Named it LoginComp
    2. Based on Panel
    3. Removed height and width values
    4. flash builder new flex component

Package explorer
flash builder package explorer

MyApp.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" creationComplete="application1_creationCompleteHandler(event)">	
	<fx:Script>
		<![CDATA[
			import components.LoginComp;
			
			import mx.events.FlexEvent;
			
			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				var loginComp:LoginComp = new LoginComp();
				loginComp.top = 300;
				loginComp.left = 300;
				this.contentGroup.addElement(loginComp);
			}
			
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>		
</s:Application>

LoginComp.mxml


<?xml version="1.0" encoding="utf-8"?>
<s: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"
		 currentState="Login" title="Please Log In" title.Register="Please Register">
	
	<fx:Script>
		<![CDATA[
			protected function button1_clickHandler(event:MouseEvent):void
			{
				if(this.currentState == "Register") {
					currentState = "Login";
				} else if(this.currentState == "Login") {
					currentState = "Register";
				}
			}
		]]>
	</fx:Script>
	
	<s:states>
		<s:State name="Login"/>
		<s:State name="Register"/>
	</s:states>
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<s:layout>
		<s:VerticalLayout paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10"/>		
	</s:layout>
	<s:HGroup verticalAlign="middle">
		<s:Label text="Username" width="80"/>
		<s:TextInput id="username"/>
	</s:HGroup>
	<s:HGroup verticalAlign="middle">
		<s:Label text="Password" width="80"/>
		<s:TextInput id="password" displayAsPassword="true"/>
	</s:HGroup>
	<s:HGroup verticalAlign="middle" includeIn="Register">
		<s:Label text="Email" width="80"/>
		<s:TextInput id="email"/>
	</s:HGroup>
	<s:HGroup verticalAlign="middle" includeIn="Register">
		<s:Label text="Phone" width="80"/>
		<s:TextInput id="phone"/>
	</s:HGroup>
	<s:controlBarContent>
		<s:Button label="Login" label.Register="Register"/>
		<s:Spacer width="100%"/>
		<s:Button label="New User" label.Register="Existing User" click="button1_clickHandler(event)"/>
	</s:controlBarContent>
</s:Panel>

Login state
login state

Register State
register state

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: