ActionScript 3 help ! : )

Thread Solved

Join Date: Apr 2008
Posts: 27
Reputation: DevC++4.9.9.2 is an unknown quantity at this point 
Solved Threads: 1
DevC++4.9.9.2 DevC++4.9.9.2 is offline Offline
Light Poster

ActionScript 3 help ! : )

 
0
  #1
Aug 9th, 2009
Hola, Im an experienced coder, however new to java/actionscript 3

I am trying to make a very simple login and I am running into problems. They seem to be with my for loop with the .Length() function in particular...

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. stop();
  2. loginError.visible = false;
  3. var loginXml:XML;
  4. var loader:URLLoader = new URLLoader();
  5. loader.load(new URLRequest("logindata.xml"));
  6. loader.addEventListener(Event.COMPLETE, loadXML);
  7. var loginData = new Array();
  8. var temp:Array = new Array();
  9. function loadXML(e:Event):void
  10. {
  11. loginXml = new XML(e.target.data);
  12. var total = loginXml.item.length();
  13. var x:int = 0;
  14. for(x=0; x < total; x++)
  15. {
  16. loginData[x] = new Array();
  17. loginData[x][0] = loginXml.item[x].user.toString();
  18. loginData[x][1] = loginXml.item[x].pass.toString();
  19. }
  20.  
  21. }
  22. loginBtn.addEventListener(MouseEvent.CLICK, loginFunction2);
  23.  
  24. function loginFunction2(e:MouseEvent):void
  25. {
  26. var success:Boolean = false;
  27. //SEEMS TO BE WHERE MY ERROR STARTS
  28. var lengthLD:int = loginData.length();
  29. for(var i=0; i < lengthLD; i++) //Most Likley the Error
  30. {
  31. if(user.text == loginData[i][0] && pass.text == loginData[i][1])
  32. {
  33. success = true;
  34. gotoAndStop(user.text);
  35. }
  36. }
  37. if(!success)
  38. {
  39. loginError.visible = true;
  40. }
  41. }


Any help would be great,
Thanks : )
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: ActionScript 3 help ! : )

 
1
  #2
Aug 10th, 2009
I'd just make a global variable

var loginXml:XML;
var loader:URLLoader = new URLLoader(); 
loader.load(new URLRequest("logindata.xml"));
loader.addEventListener(Event.COMPLETE, loadXML);
var loginData = new Array();
var temp:Array = new Array();


var gtotal:int = 0;

function loadXML(e:Event):void
{
    loginXml = new XML(e.target.data);
	gtotal = loginXml.item.length();	
                var x:int = 0;
	for(x=0; x < gtotal; x++)
	{
		loginData[x] = new Array();
		loginData[x][0] = loginXml.item[x].user.toString();
		loginData[x][1] = loginXml.item[x].pass.toString();
		
		//trace it out
		//trace(loginData[x][1]);
		
		
	}
	
	//trace(gtotal);
	
}

button1.addEventListener(MouseEvent.CLICK, go);
function go(e:MouseEvent)
{
  var success:Boolean = false;

   
	for(var i=0; i < gtotal; i++)                   //Most Likley the Error
	{
		if(user.text == loginData[i][0] && pass.text == loginData[i][1])
		  {
			  success = true;
			  //gotoAndStop(user.text);
		  }
	}
	if(!success)
	{
		//loginError.visible = true;
	}
	
	trace(success);

}


my xml file:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. <root>
  2. <item>
  3. <user>john</user>
  4. <pass>password</pass>
  5. </item>
  6. <item>
  7. <user>sally</user>
  8. <pass>hello</pass>
  9. </item>
  10. </root>
Last edited by iamthwee; Aug 10th, 2009 at 6:18 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 151
Reputation: rajarajan07 is on a distinguished road 
Solved Threads: 21
rajarajan07's Avatar
rajarajan07 rajarajan07 is offline Offline
Junior Poster

Re: ActionScript 3 help ! : )

 
0
  #3
Aug 10th, 2009
In AS 3.0, its very simple to find the length.

Step 1:

Use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var loginform:XMLList;
  2. var total:Number=0;

instead of :

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var gtotal:int = 0;


Step 2:

use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. total = loginform.length();

instead of:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. gtotal = loginXml.item.length();


Sure It will work, if yes, mark as solved. Thanks
Thanks & Regards,
RajaRajan. R

trulyraja2009@yahoo.in
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 151
Reputation: rajarajan07 is on a distinguished road 
Solved Threads: 21
rajarajan07's Avatar
rajarajan07 rajarajan07 is offline Offline
Junior Poster

Re: ActionScript 3 help ! : )

 
0
  #4
Aug 10th, 2009
I looked into your code and executed the half, but your method of total is perfectly working.
Thanks & Regards,
RajaRajan. R

trulyraja2009@yahoo.in
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 151
Reputation: rajarajan07 is on a distinguished road 
Solved Threads: 21
rajarajan07's Avatar
rajarajan07 rajarajan07 is offline Offline
Junior Poster

Re: ActionScript 3 help ! : )

 
3
  #5
Aug 10th, 2009
Mr. DevC++4.9.9.2,

I am so sorry I am confused forget all those things said above, that is also correct, but in your program nothing is wrong except you have to remove two parenthesis in length function, thats it done.

var lengthLD:int = loginData.length;
Thanks & Regards,
RajaRajan. R

trulyraja2009@yahoo.in
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: ActionScript 3 help ! : )

 
0
  #6
Aug 10th, 2009
Yep post #5 was the correct answer, or should I say the shortest answer/fix.
Last edited by iamthwee; Aug 10th, 2009 at 8:26 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 27
Reputation: DevC++4.9.9.2 is an unknown quantity at this point 
Solved Threads: 1
DevC++4.9.9.2 DevC++4.9.9.2 is offline Offline
Light Poster

Re: ActionScript 3 help ! : )

 
0
  #7
Aug 10th, 2009
Thank you very much... This answer worked... I am coming from c++ and these little things are ganna kill me lol

My final code:
Graphics and Multimedia Syntax (Toggle Plain Text)
  1. stop();
  2. loginError.visible = false;
  3. var loginXml:XML;
  4. var loader:URLLoader = new URLLoader();
  5. loader.load(new URLRequest("logindata.xml"));
  6. loader.addEventListener(Event.COMPLETE, loadXML);
  7. var loginUser:Array = new Array();
  8. var loginPass:Array = new Array();
  9. var total:Number = 0;
  10. function loadXML(e:Event):void
  11. {
  12. loginXml = new XML(e.target.data);
  13. total = loginXml.length();
  14. var x:Number = 0;
  15. for(x=0; x < total; x++)
  16. {
  17. loginUser.push(loginXml.item[x].user.toString());
  18. loginPass.push(loginXml.item[x].pass.toString());
  19. }
  20. }
  21. loginBtn.addEventListener(MouseEvent.CLICK, loginFunction);
  22.  
  23. function loginFunction(e:MouseEvent):void
  24. {
  25. var success:Boolean = false;
  26. var i:Number = 0;
  27. for(i=0; i < total; i++)
  28. {
  29. if(user.text == loginUser[i] && pass.text == loginPass[i])
  30. {
  31. success = true;
  32. gotoAndStop(user.text);
  33. }
  34. }
  35. if(!success)
  36. {
  37. loginError.visible = true;
  38. }
  39. }


thanks again

Originally Posted by rajarajan07 View Post
In AS 3.0, its very simple to find the length.

Step 1:

Use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var loginform:XMLList;
  2. var total:Number=0;

instead of :

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var gtotal:int = 0;


Step 2:

use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. total = loginform.length();

instead of:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. gtotal = loginXml.item.length();


Sure It will work, if yes, mark as solved. Thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Graphics and Multimedia Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC