Copy link to clipboard
Copied
Hi guys,
I'm really new to actionscript so i have trouble in understanding the code. I tried many ways to go to a new scene after login successful but sadly failed. I followed one of the tutorials on the login part..It works and i'm happy wif it..but currently, it displays only the success message. Instead, i wanna go to a new scene but don't know how. I'll post the code below. Hope u can help ..I have a dateline for this project. Thanks!
[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]
<?php
include_once "dbconnect.php";
$username = $_POST['username']; //variables from flash
$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!";
}
}
?>
You probably want to check the value that it returns and use it to decide whether to go to the next scene or not.
public function showResult (event:Event):void {
result_text.autoSize = TextFieldAutoSize.LEFT;
result_text.text = "" + event.target.data.systemResult;
if(String(result_text.text).indexOf("Welcome") == 0) {
gotoAndPlay(1, "Scenename");
}
}
What the first line does is checks
...Copy link to clipboard
Copied
You probably want to check the value that it returns and use it to decide whether to go to the next scene or not.
public function showResult (event:Event):void {
result_text.autoSize = TextFieldAutoSize.LEFT;
result_text.text = "" + event.target.data.systemResult;
if(String(result_text.text).indexOf("Welcome") == 0) {
gotoAndPlay(1, "Scenename");
}
}
What the first line does is checks to see if the word Welcome is at the start of whatever is in the textfield (starts at index 0). If it does, then it issues the command to move to another frame/scene
Copy link to clipboard
Copied
It works!!! Thank you very very much!! Oh ya, i was thinking of doing update and view/display as well. Can i use the same code above and change a bit here and there? If so, any parts i should look out for?
Copy link to clipboard
Copied
Chances are whatever you mean to do you can do. You'll have to explain more about what you mean. You should start a new posting if you run into a problem and need help with it.
Copy link to clipboard
Copied
Ok then. I believe i will run into problems and start posting again..haha By the way, thanks again for your help