Solved

Flash Actionscript 3 login script not working

Posted on 2010-11-14
12
522 Views
Last Modified: 2013-11-11
Hi,

I have been trying to get a simple login script to work in Flash CS3 and after following an online tutorial it is running fine with no errors however when I enter the correct username and password combination it always say ‘incorrect username or password’ from the else part of the IF statement rather than the code gotoAndPlay () part if the details are correct.

Here is the code I have been using it is on frame 470 and when the details are correct it should go to frame 471 and play the intro to the members area:

 
stop();

var cMenu:ContextMenu = new ContextMenu();
cMenu.hideBuiltInItems();
contextMenu = cMenu;

passtxt.displayAsPassword = true; 

loginBtn.buttonMode = true;

loginBtn.addEventListener(MouseEvent.CLICK, loginFunction);

function loginFunction(e:MouseEvent):void{
	
	if(usertxt.text == "guest" && passtxt.text == "pass"){
		gotoAndPlay(472);
		
	}else{
		
		var fmt:TextFormat = new TextFormat();
		fmt.color = 0xff0000;
		statusTxt.text = "Incorrect username or password";
		statusTxt.setTextFormat(fmt);
	}
}

Open in new window


Thank you for any help you can provide.
Karl
0
Comment
Question by:Karl01
  • 5
  • 4
  • 2
12 Comments
 
LVL 5

Assisted Solution

by:GarrettChristopherson
GarrettChristopherson earned 50 total points
ID: 34133075
I know that this isn't a direct solution, but a method to collect information to find the problem.

add a textfield to your .swf, and then before the conditional, add the values of the textInput(in this case usertxt.text and passtxt.text) to the new textfield so that one can see actual values.  

so,

stop();



var cMenu:ContextMenu = new ContextMenu();

cMenu.hideBuiltInItems();

contextMenu = cMenu;



passtxt.displayAsPassword = true; 



loginBtn.buttonMode = true;



loginBtn.addEventListener(MouseEvent.CLICK, loginFunction);



function loginFunction(e:MouseEvent):void{

	

viewTxt.text = usertxt.text + " = username password = " + passtxt.text; 



	if(usertxt.text == "guest" && passtxt.text == "pass"){

		gotoAndPlay(472);

		

	}else{

		

		var fmt:TextFormat = new TextFormat();

		fmt.color = 0xff0000;

		statusTxt.text = "Incorrect username or password";

		statusTxt.setTextFormat(fmt);

	}

}

Open in new window

0
 

Author Comment

by:Karl01
ID: 34140563
Hi GarrettChristopherson, sorry for the late replay it has been a really busy day, I inserted the extra code:

viewTxt.text = usertxt.text + " = username password = " + passtxt.text;

and I got the output of guest = username and password = pass so it is handling the inputs fine and they do match the start of the IF statement, there must be something wrong with the implementation of the IF statement, but I don’t know what.  

Any ideas?

Thanks
Karl
0
 
LVL 5

Expert Comment

by:GarrettChristopherson
ID: 34141723
I would then trace before and after the gotoAndStop(472) statement, and then place another trace statement on frame 472 to ensure that it is going there.  

I you notice some weird stuff happening, I now in older versions of flash (MX2004 pro AS2.0) that sometimes I would have to retype lines of code and change the names of variables and such to get things aligned...
0
 

Author Comment

by:Karl01
ID: 34168708
Hi GarrettChristopherson,

I have placed the trace statement within the if statement {function brackets} and get the same output that match the if statement condition however it will still not let me progress to the gotoAndStop part. I just cant figure out what is wrong it has no errors the code sort of works as it take the input and can be send back as an output and the else part is functional i.e. if I swap the functions then it will go straight to the page requested.

Do you have any more ideas on what might be going wrong?
Thanks for looking at this.
Karl
0
 
LVL 5

Expert Comment

by:GarrettChristopherson
ID: 34168912
I can have an over active imagination at times, and proving my theory would take more time than I have by myself at this moment in time.  With that in mind, I think that there could be some kind of gathering of instructions and data that is either intentional or unintentional on one or more programmer's part, and thus could cause some unpredictable behavior.  Sometimes, retyping the line would help, sometimes repeating a process with the program can help unlock some kind of linkage, or sometimes there is something seemingly unrelated causing the issue.  I think this could happen because of the difficult nature of the problem of organizing all the data and instructions that is being created/related/organized/etc.

Some programs like it when the operator uses another feature that hasn't been used yet...that one I'm pretty sure has been achieved, so, try giving the frame a name, and then use gotoAndStop("frameLabel");
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Karl01
ID: 34189615
Hi GarrettChristopherson,

I have created a new flash file and got the code to work but it will not work in my students flash file and he has retyped it and tried a few things their is just something not right that I am not able to spot. I have attached the flash file if you would not mind taking a quick look to see if there are some elements in the wrong places etc.

Regards
Karl



 Final-Website-Animation.fla
0
 
LVL 5

Expert Comment

by:GarrettChristopherson
ID: 34189833
I'm sorry, my company has a very strict policy on downloading files.  Please don't take it personally, as this is not a reflection on your correspondence with me, rather, it is both a intellectual and computer security matter.  I can only have files on my computer that I generate.  Hopefully someone else can help!
0
 
LVL 10

Expert Comment

by:Carnou
ID: 34233489
in the fla you included, your if statement says:
      if (usertxt.text == "guest" + passtxt.text == "pass"){

While in the code snippet you put above, you have the correct answer:
      if(usertxt.text == "guest" && passtxt.text == "pass"){

Fixing that should solve your problem.
0
 

Author Comment

by:Karl01
ID: 34304405
Hi Carnou,

I have changed the code as you suggested but it has not changed the outcome the && worked in the script in a new flash file yet it will not work in the actual students project file, I just cant figure out why. Have you managed to get the code working in the example flash file I uploaded?

Thank you for your help in looking at this and sorry for the late reply I have been really busy with other students projects and had to put the login scripts to the back for a week.

Best regards
Karl
0
 
LVL 10

Accepted Solution

by:
Carnou earned 450 total points
ID: 34306022
As a matter of fact, I have gotten it to succeed, but only just now, and only by fixing the underlying issues.

First of all, you do need to change the + in line 18 back to a &&.  Without this, it won't work.

Secondly, the underlying issue was that usertxt and passtxt were set with their Behavior to Multiline.  Setting the behaviors to Single Line (and fixing the logic issue mentioned above) made it all work fine.

I glanced around online, but couldn't find docs from Adobe as to what the difference is between Multiline and Single Line (besides the obvious visible differences), but in some way, it affects the string that is returned.
0
 

Author Closing Comment

by:Karl01
ID: 34335155
Hi Carnou,

That has worked fine thank you very much, you have one elated and relived student and a very grateful teacher here. I like a simple fix but that was frustrating I just could not spot it or even think to try the input box options as a cause.

I have awarded some point to GarrettChristopherson as he help at the start and gave me some good pointers, hope that’s ok.

Regards
Karl
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now