Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.23 / 5.00 3,881 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.93 / 5.00 4,634 ViewsHere is the script
stop();
//Declear Array
var UserArray:Array = [];
var PassArray:Array = [];
//Declear Flag
var Flag:Boolean = false;
//Declear Your URLLoader
var UserDataLoader:URLLoader = new URLLoader ;
//Declaer Your URLLoade as to read as Variable
UserDataLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
//Declear EventListener for your URLLoader
UserDataLoader.addEventListener(Event.COMPLETE,onLoaded);
function onLoaded(e:Event):void
{
UserArray = e.target.data.Username;
PassArray = e.target.data.Password;
trace("Your File have been Loaded");
}
//Load your file
UserDataLoader.load(new URLRequest("Users_Password_Data.txt"));
//Declear EventListener for your button;
btn_Login.addEventListener(MouseEvent.CLICK,LoginEvent);
//Declear Function for your EventListener;
function LoginEvent(e:MouseEvent):void
{
trace("The Login Button was clicked");
for (var i:Number=0; i<=UserArray.length || Flag == true; i++)
{
trace(UserArray[i]);
trace(user_textbox.text);
trace(PassArray[i]);
trace(pass_textbox.text);
trace(Flag);
if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
{
Flag = true;
}
i++;
}
if (Flag== true){
gotoAndStop(2);
}
}
this.btn_Login.removeEventListener(Event.ENTER_FRAME,LoginEvent);
The script work fine!
but it never satisfy this condition:
if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
{
Flag = true;
}
even though the value are equal! any help to make this condition work?!
text value:
Username=A
&Username=B
&Username=C
&Username=D
&Username=E
&Password=1
&Password=2
&Password=3
&Password=4
&Password=5
A with 1
B with 2
C with 3
D with 4
E with 5
If the flag becomes true in your for loop, it will run infinitely.
At 10/22/13 08:31 AM, kkots wrote: If the flag becomes true in your for loop, it will run infinitely.
why it will run infinitely?! wasn't the for loop tells me if the condition is satisfied then exit the loop?!
At 10/22/13 10:09 AM, A-Genius wrote:At 10/22/13 08:31 AM, kkots wrote: If the flag becomes true in your for loop, it will run infinitely.why it will run infinitely?! wasn't the for loop tells me if the condition is satisfied then exit the loop?!
Put the flag part in the loop instead of in the for statement, you're probably confusing yourself.
At 10/22/13 10:09 AM, A-Genius wrote: wasn't the for loop tells me if the condition is satisfied then exit the loop?!
Just set a breakpoint and debug your code. Stop the guesswork.
At 10/22/13 11:08 AM, MSGhero wrote: Put the flag part in the loop instead of in the for statement, you're probably confusing yourself.
At 10/22/13 01:51 PM, milchreis wrote: Just set a breakpoint and debug your code. Stop the guesswork.
Thanks for the help everyone!
At 10/22/13 11:08 AM, MSGhero wrote:
I fixed the previous but that didn't change the fact that the actual problem is that:
if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
{
Flag = true;
}
this condition never satisfied ! even thought the value of the textboxs equal to the arrays
When you change your code, post the new code.
Make sure you use the code tags this time.
At 10/22/13 11:07 PM, milchreis wrote: When you change your code, post the new code.
Make sure you use the code tags this time.
stop();
//Declear Array
var UserArray:Array = [];
var PassArray:Array = [];
//Declear Flag
var Flag:Boolean = false;
//Declear Your URLLoader
var UserDataLoader:URLLoader = new URLLoader ;
//Declaer Your URLLoade as to read as Variable
UserDataLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
//Declear EventListener for your URLLoader
UserDataLoader.addEventListener(Event.COMPLETE,onLoaded);
function onLoaded(e:Event):void
{
UserArray = e.target.data.Username;
PassArray = e.target.data.Password;
trace("Your File have been Loaded");
}
//Load your file
UserDataLoader.load(new URLRequest("Users_Password_Data.txt"));
//Declear EventListener for your button;
btn_Login.addEventListener(MouseEvent.CLICK,LoginEvent);
//Declear Function for your EventListener;
function LoginEvent(e:MouseEvent):void
{
trace("The Login Button was clicked");
for (var i:Number=0; i<=UserArray.length; i++)
{
trace(Flag);
if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
{
Flag = true;
}
i++;
}
if (Flag== true){
gotoAndStop(2);
}
}
this.btn_Login.removeEventListener(Event.ENTER_FRAME,LoginEvent); Ok, now we can take a look.
First of all: Do you know that this is not secure at all?
Client side user authentication tends to be insecure.
What's the point of the Flag variable besides what it does in your code?
If you want to check the condition and goto a different frame, just do that. No need to set flag variables that aren'T used elsewhere.
Give proper names to your variables.
You for loop seems to be wrong. (It is)
This is really fundamental stuff.
Take that for loop, just the for loop without anything inside it and put it into an empty project.
Trace i on every iteration (or use the debugger) and think about if is the way it's meant to be. (It's not)
Why do you remove a listener for ENTER_FRAME Event that is never added?
Why do you increment i in the loop?