
January 4th, 2013, 09:47 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 35 m 57 sec
Reputation Power: 0
|
|
|
ActionScript 3 - Actionscript 3 > php > mysql (new flash scene after login successful)
Hi guys,
I'm currently having my final year project now and i really need help as i'm very new to actionscript 3.0 > php > mysql connection. I feel so ridiculous to not know how to solve this "simple login code". I'm not sure whether i should add the code in php or actionscript file. But, here goes...
Currently, after the button is being clicked, a successful message will appear --> print "systemResult=Welcome $username!";.
As you can see from the title of my thread, i want it to go to a new scene instead (in flash). I tried so many ways to do it but sadly, it didn't work. Or mayb i'm just doing it wrong, i don't know. I really need help on this!!! Thanks guys!
[Actionscript]
package actions {
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.text.*;
public class main extends MovieClip {
public function main ():void {
submit_button.buttonMode = true;
submit_button.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);
username.text = "";
password.text = "*";
}
public function checkLogin (e:MouseEvent):void {
if (username.text == "" || password.text == "") {
if (username.text == "") {
username.text = "Enter your username";
}
if (password.text == "") {
password.text = "Enter your password";
}
} else {
processLogin();
}
}
public function processLogin ():void {
var phpVars:URLVariables = new URLVariables();
var phpFileRequest:URLRequest = new URLRequest("login.php");
phpFileRequest.method = URLRequestMethod.POST;
phpFileRequest.data = phpVars;
var phpLoader:URLLoader = new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpLoader.addEventListener(Event.COMPLETE, showResult);
phpVars.systemCall = "checkLogin";
phpVars.username = username.text;
phpVars.password = password.text;
phpLoader.load(phpFileRequest);
}
public function showResult (event:Event):void {
result_text.autoSize = TextFieldAutoSize.LEFT;
result_text.text = "" + event.target.data.systemResult;
}
}
}
[php] - login.php
<?php
include_once "dbconnect.php";
$username = $_POST['username'];
$password = $_POST['password'];
if ($_POST['systemCall'] == "checkLogin") {
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$query = mysql_query($sql);
$login_counter = mysql_num_rows($query);
if ($login_counter > 0) {
print "systemResult=Welcome $username!";
} else {
print "systemResult=Invalid User!";
}
}
?>
|