Les cuento que realice una animacion, a la cual al final le agregue un formulario. Mi problema es que cuando aprieto el boton login del formulario al parecer no pasa nada. SIn embargo, si luego entro a otro pagina sucede que la accion del login funciono. Lo que yo quiero que suceda es que al apretar el login, me rediriga automaticamente a la pagina que yo quiero. (Aclaro que si el login es en html/php funciona perfecto).Otra aclaracion, el submit_btn lo probe siendo mc y como boton sin obtener el resultado esperado.
Les dejo mi codigo de AS3.
Código :
stop();
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.sendToURL;
submit_btn.addEventListener(MouseEvent.MOUSE_DOWN, onEnviar);
submit_btn.buttonMode = true;
submit_btn.useHandCursor = true;
function onEnviar(obj:Event) {
var urlVars:URLVariables = new URLVariables();
urlVars.usuario = usuario.text;
urlVars.password = password.text;
var urlRequ:URLRequest = new URLRequest("validar_usuario.php");
urlRequ.method = URLRequestMethod.POST;
urlRequ.data = urlVars;
var urlLoad:URLLoader = new URLLoader();
urlLoad.load(urlRequ);
}
Aca les dejo mi php por las dudas.
Código :
<? // Pedazo de codigo para entrar a la base de datos
if(trim($HTTP_POST_VARS["usuario"]) != "" && trim($HTTP_POST_VARS["password"]) != "")
{
// Puedes utilizar la funcion para eliminar algun caracter en especifico
//$usuario = strtolower(quitar($HTTP_POST_VARS["usuario"]));
//$password = $HTTP_POST_VARS["password"];
// o puedes convertir los a su entidad HTML aplicable con htmlentities
$usuario = strtolower(htmlentities($HTTP_POST_VARS["usuario"], ENT_QUOTES));
$password = $HTTP_POST_VARS["password"];
$result = mysql_query('SELECT password, usuario FROM usuarios WHERE usuario=\''.$usuario.'\'');
if($row = mysql_fetch_array($result)){
if($row["password"] == $password){
$_SESSION["k_username"] = $row['usuario'];
$_SESSION["k_password"] = $row['password'];
header ("Location: listadevideos.php");
// echo 'Has sido logueado correctamente '.$_SESSION['k_username'].' <p>';
// echo '<a href="index.php">Index</a></p>';
}else{
echo 'Password incorrecto';
}
}else{
echo 'Usuario no existente en la base de datos';
}
mysql_free_result($result);
}else{
echo 'Debe especificar un usuario y password';
}
mysql_close();
?>Por ultimo les quiero decir, que he probado un formulario en as2 ( que no puedo utilizar en mi caso ya que esta todo lo demas hecho con as3 y se complicaria demasiado adaptarlo) y al principio tenia el mismo problema con este codigo:
Código :
stop();
// Create 2 LoadVars objects to load and send data to the PHP script
var loader:LoadVars = new LoadVars();
var sender:LoadVars = new LoadVars();
status = "Enter your information and submit";
// When the submit button is pressed...
submit_btn.onRelease = function() {
// assign the text in the input fields to the sender object
sender.usuario = usuario.text;
sender.password = password.text;
// and then send it on to the PHP file on the server using
// the POST method. The returned result will be caught
// by the loader object
sender.sendAndLoad("validar_usuario.php", loader, "POST");
}
// The loader object waits for a response from the server
// and checks for any returned variables, messages, errors.
loader.onLoad = function(success:Boolean)
{
// This boolean variable (success) will return true or false
// on whether the PHP file was retrieved
if(success)
{
// If we're here then we've successfully retrieved
// the PHP file. Lets check for a Login result
if(this.checklog == 1)
{
// This is a authorised login so show the success frame
// and show the message in the status textfield
status = this.status;
_parent.gotoAndStop("Success");
}
else if(this.checklog == 2)
{
// This is a unauthorised login so show the failure frame
// and show the error message in the status textfield
status = this.status;
_parent.gotoAndStop("Invalid");
}
}
else {
// There was a problem retrieving the PHP file
status = "Error connecting to server";
}
}y luego lo solucione cambiando
Código :
sender.sendAndLoad("validar_usuario.php", loader, "POST");por
Código :
sender.send("validar_usuario.php", loader, "POST");Esto lo pongo para ver si hay alguna semejanza en as3.
Muchas gracias a todos
Matias
