topical media & game development
server-amf-login-comps-Login.mx
server-amf-login-comps-Login.mx
(swf
)
[ flash
]
flex
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" verticalAlign="middle">
<mx:states>
<mx:State name="succes">
<mx:RemoveChild target="{loginForm}"/>
<mx:RemoveChild target="{alertTxt}"/>
<mx:AddChild relativeTo="{hbox1}" position="lastChild">
<mx:TextArea height="64" fontFamily="Arial" fontSize="12">
<mx:text>Je login was succesvol. Klik op de button om verder te gaan</mx:text>
</mx:TextArea>
</mx:AddChild>
<mx:SetProperty target="{loginButton}" name="label" value="Ga verder"/>
</mx:State>
</mx:states>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public var valid:Boolean = false;
private var gateway:NetConnection;
private var gatewayURL:String = "http://localhost.nl/amfphp/gateway.php"
private function setConnection() : void {
gateway = new NetConnection;
gateway.connect(gatewayURL);
}
public function doLogin(event:Event) : void {
trace('CLICKED');
loginButton.addEventListener(MouseEvent.CLICK, loginHandler);
}
private function loginHandler(event:MouseEvent) : void {
trace('Do Login');
alertTxt.text = "Een ogenblik alsjeblieft. Bezig met laden.";
var responder:Responder = new Responder(loginRespHandler, returnFault);
setConnection();
gateway.call("TestDB.login", responder, loginCol.text, passwordCol.text);
}
private function returnFault(obj:Object) : void {
Alert.show("Error has accured");
}
private function loginRespHandler(o:Object) : Boolean {
trace('Response: ' + o.response);
if(o.response) {
valid = true;
trace('GEBRUIKER');
currentState='succes';
} else {
valid = false;
trace('GEEN GEBRUIKER');
alertTxt.text = "Gebruikersnaam en/of wachtwoord onjuist.";
}
return valid;
}
]]>
</mx:Script>
<mx:VBox verticalGap="0" id="vbox1">
<mx:Panel
title="Login" id="loginPanel"
horizontalScrollPolicy="off" verticalScrollPolicy="off" backgroundAlpha="0.3">
<mx:Form id="loginForm">
<mx:FormItem label="Gebruikersnaam:" required="true" id="formitem1">
<mx:TextInput id="loginCol"/>
</mx:FormItem>
<mx:FormItem label="Wachtwoord:" required="true" id="formitem2">
<mx:TextInput id="passwordCol" displayAsPassword="true"/>
</mx:FormItem>
</mx:Form>
<mx:VBox width="100%" id="hbox1" horizontalAlign="center">
<mx:Text id="alertTxt" color="#FF0909" fontSize="11" selectable="false" width="100%" fontWeight="bold"/>
</mx:VBox>
<mx:ControlBar id="controlbar1">
<mx:Spacer width="100%" id="spacer1"/>
<mx:Button label="Login" id="loginButton"
enabled="{(loginCol.text.length == 0 || passwordCol.text.length == 0) ? false : true}"
useHandCursor="true" buttonMode="true"/>
</mx:ControlBar>
</mx:Panel>
</mx:VBox>
</mx:VBox>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.