Created
September 26, 2013 01:44
-
-
Save azcdev/6708742 to your computer and use it in GitHub Desktop.
Archivo de la pelicula con todos los elementos de la interfaz de usuario para autentificar a un usuario usando PHP, XML y MySQL desde AS3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import flash.display.*; | |
import flash.net.*; | |
import flash.events.*; | |
import flash.text.*; | |
public class main extends MovieClip { | |
private static const DEFAULT_TEXT:String = "Iniciando Test..."; | |
private static const dx:int = 400; | |
private static const URL:String = "index.php"; | |
private var _loader:URLLoader; | |
private var _request:URLRequest; | |
private var _requestVars:URLVariables; | |
public var usuario:TextField = new TextField(); | |
public var contrasena:TextField = new TextField(); | |
public var usuarioLbl:TextField = new TextField(); | |
public var contrasenaLbl:TextField = new TextField(); | |
public var botonLogin:MovieClip = new MovieClip(); | |
public var campo:TextField = new TextField(); | |
public function main() { | |
usuario.type = TextFieldType.INPUT; | |
usuario.background = true; | |
usuario.border = true; | |
usuario.height = 20; | |
usuario.x = 300; | |
usuario.y = 150; | |
addChild(usuario); | |
usuarioLbl.text = "Nombre de usuario:"; | |
usuarioLbl.x = 170; | |
usuarioLbl.y = 150; | |
addChild(usuarioLbl); | |
contrasena.type = TextFieldType.INPUT; | |
contrasena.background = true; | |
contrasena.displayAsPassword = true; | |
contrasena.border = true; | |
contrasena.height = 20; | |
contrasena.x = 300; | |
contrasena.y = 200; | |
addChild(contrasena); | |
contrasenaLbl.text = "Contraseña:"; | |
contrasenaLbl.x = 170; | |
contrasenaLbl.y = 200; | |
addChild(contrasenaLbl); | |
botonLogin.graphics.beginFill(0x0000FF); | |
botonLogin.graphics.drawRect(0,0,100,20); | |
botonLogin.graphics.endFill(); | |
botonLogin.x = (contrasenaLbl.x + contrasenaLbl.width + contrasena.x + contrasena.width)/2-botonLogin.width; | |
botonLogin.y = 250; | |
botonLogin.addEventListener(MouseEvent.CLICK,autenticarUsuario); | |
addChild(botonLogin); | |
campo.border = true; | |
campo.width = 400; | |
campo.height= 100; | |
campo.x = botonLogin.x-150; | |
campo.y = 300; | |
campo.text = DEFAULT_TEXT; | |
addChild(campo); | |
} | |
public function autenticarUsuario(e:MouseEvent):void{ | |
output("Validando Usuario..."); | |
if((usuario.text=="")||(contrasena.text=="")) { | |
output("Campo de usuario o contrasena está vacíon"); | |
} else { | |
_requestVars = new URLVariables(); | |
_requestVars.usr = usuario.text; | |
_requestVars.pwd = contrasena.text; | |
_request = new URLRequest(URL); | |
_request.method = URLRequestMethod.POST; | |
_request.data = _requestVars; | |
_loader = new URLLoader(); | |
_loader.addEventListener(Event.COMPLETE,completado); | |
_loader.load(_request); | |
} | |
} | |
public function output(s:String):void | |
{ | |
campo.appendText(s+"n"); | |
} | |
public function completado(e:Event) | |
{ | |
output("Consulta completada!n"); | |
output("Mostrando Infomación:n"); | |
var xml:XML = new XML(e.target.data); | |
var campos:XMLList = xml..result; | |
if(campos[0].ID == -1) { | |
output("Usuario no existe"); | |
} else { | |
output("Usuario autentificado con ID: "+campos[0].ID); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment