Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : Some advice please


ActionScripter1
2/25/2006 9:03:00 PM
Hi Guys,

I am attempting to create a login screen which sends and loads the variables
using php, php will query the database and print out a variable which wil then
be loaded back into flsh and tell flash which frame to go to.

the little issue I'm having is, I did this two weeks ago and it all worked
great, now I would like to do it again but when the php file is unavailable the
statusmsg label box does not say Login Failed like it should.

What am I doing wrong and is it trying to reconnect like it should if the
variables were not loaded.

//Define a new Variable called (submitlistener)
var submitListener:Object = new Object();

//Listen for the Button Click
submitListener.click = function(evt:Object) {

//Set a message in the Label object called statusmsg for tracking
statusmsg.text = "Connecting to Server";

//Define a new LoadVars Object for storing the recieved Variables in
var result_lv:LoadVars = new LoadVars();

//Listen for the Variables to be loaded
result_lv.onLoad = function(success:Boolean) {

//If the Variables were loaded, check to see if they were undefined or empty
if (success) {
framejump = result_lv.template;
if (framejump == undefined) {

//Set a message in the Label object called statusmsg for tracking
statusmsg.text = "Login Failed - Retrying...";

//resend the Variables (userinput, passinput) and Load the Result Variables
from the PHP file in to result_lv
send_lv.sendAndLoad("login.php", result_lv, "POST");
} else {

//Go to Frame Label (loggedin) = Frame 2 if all Variables were set and did not
= undefined
gotoAndPlay(LoggedIn);
}
} else {

//Set a message in the Label object called statusmsg for tracking
statusmsg.text = "Connecting to Secondary Server";

//resend the Variables (userinput, passinput) and Load the Result Variables
from the PHP file in to result_lv
send_lv.name = userinput.text;
send_lv.name = passinput.text;
send_lv.sendAndLoad("login.php", result_lv, "POST");
}
}
};
//Define a new Load Vars Object which will post all the variables using prefix
(send_lv.name)
var send_lv:LoadVars = new LoadVars();

//Send the Variables (userinput, passinput) and Load the Result Variables from
the PHP file in to result_lv
send_lv.name = this.userinput.text;
send_lv.name = this.passinput.text;
send_lv.sendAndLoad("login.php", result_lv, "POST");


//Define an Event Listenter for the Connect Button Being Pressed
connect_button.addEventListener("click", submitListener);

//Prevent from going to the next Frame
stop();

Any suggestions on code improvement will be greatly appreciated.
blemmo
2/26/2006 4:56:24 PM
Hi,

your code was a bit scrambled (the sender LoadVars was outside the button and
stated to use result_lv, when result_lv wasn't created).
I fixed that and added a counter variable 'tries', to enable retrying for a
certain amount of times (your first version would have never stopped retrying
if the login was wrong).
Speaking of the login... when it was wrong ("if framejump == undefined") why
resend the variables? I think you should just stop to enable the user to put in
another name/password.

greets,
blemmo

ps: please attach such big code snippets, it's much better readable.



//Define a new Variable called (submitlistener)
var submitListener:Object = new Object();
//Listen for the Button Click
submitListener.click = function(evt:Object) {
tries = 1;
//Set a message in the Label object called statusmsg for tracking
statusmsg.text = "Connecting to Server";
//Define a new Load Vars Object which will post all the variables using
prefix (send_lv.name)
var send_lv:LoadVars = new LoadVars();
//Set the Variables to send
send_lv.name = userinput.text;
send_lv.password = passinput.text;
//Define a new LoadVars Object for storing the recieved Variables in
var result_lv:LoadVars = new LoadVars();
//Listen for the Variables to be loaded
result_lv.onLoad = function(success:Boolean) {
//If the Variables were loaded, check to see if they were undefined or empty
if (success) {
framejump = result_lv.template;
if (framejump == undefined) {
//Set a message in the Label object called statusmsg for tracking
statusmsg.text = "Login Failed - Retrying...";
tries++;
//resend the Variables (userinput, passinput) and Load the Result
Variables from the PHP file in to result_lv
send_lv.sendAndLoad("login.php", result_lv, "POST");
} else {
//Go to Frame Label (loggedin) = Frame 2 if all Variables were set and did
not = undefined
gotoAndPlay(LoggedIn);
}
} else if (tries<2) {
//Set a message in the Label object called statusmsg for tracking
statusmsg.text = "Connecting to Secondary Server";
tries++;
//resend the Variables (userinput, passinput) and Load the Result Variables
from the PHP file in to result_lv
send_lv.sendAndLoad("login.php", result_lv, "POST");
} else {
statusmsg.text = "Could not connect";
}
};
send_lv.sendAndLoad("login.php", result_lv, "POST");
};
//Define an Event Listenter for the Connect Button Being Pressed
connect_button.addEventListener("click", submitListener);
//Prevent from going to the next Frame
stop();
AddThis Social Bookmark Button